Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   System.out.println help (http://www.chiefdelphi.com/forums/showthread.php?t=98979)

Stonemotmot 21-12-2011 14:51

System.out.println help
 
Hello, I am trying to get my encoder value to print to the net console.
The only line giving me an error is.

System.out.println(encoder1.Get());

the error console says System is not defined. Any help would be appreciated.

mikets 21-12-2011 16:41

Re: System.out.println help
 
Try this instead:
Code:

printf("Encoder1=%d", encoder1.Get());

Radical Pi 21-12-2011 16:48

Re: System.out.println help
 
Judging by the use of a capital in Get(), and that you posted to the C++ forum, I'm assuming you're using C++. System.out.println isn't a thing in C, the equivalent is printf(). An example:
Code:

// Top of file
#include <stdio.h>
...
// Inside your function
printf("%d\n", encoder1.Get());

The %d means we have an integer to print, and \n means to add a newline afterwards. Look here for more info

One thing to note, however, is that excessive use of printf can sometimes flood the network and if this is being called every iteration, you'll get a ton of text in netconsole. I prefer to use the DriverStationLCD class, which will put the text on the right of the Operation tab of the driver station.
Code:

void OperatorControl(void)
{
        DriverStationLCD *dslcd = DriverStationLCD::GetInstance();
        ...
        while (IsOperatorControl())
        {
                dslcd->Clear();
                ...
                dslcd->Printf(DriverStationLCD::kUser_Line1, 1, "Left Encoder: %d", encoder1->Get());
                ...
                dslcd->UpdateLCD();
        }
}

kUser_Line1 tells it which line to go on, 1 is the column to start in (generally 1), and the rest of it is called just like the regular printf(). Make sure you include the Clear() at the top of your loop, otherwise you can get some weird stuff in the text box.

Stonemotmot 22-12-2011 12:52

Re: System.out.println help
 
Thanks, so am i correct in understanding that println is a java command not c++ which uses printf?
I will try this thanks for the help.

WizenedEE 22-12-2011 13:14

Re: System.out.println help
 
Quote:

Originally Posted by Stonemotmot (Post 1093094)
Thanks, so am i correct in understanding that println is a java command not c++ which uses printf?
I will try this thanks for the help.

It's because printf doesn't have a class to go along with it. In Java, everything must have a class (You essentially can't call a function without a . before it), but in C++ classes are optional.

hdastwb 11-01-2012 23:31

Re: System.out.println help
 
Actually, in most variants of C++ we've got things called "streams" that greatly enhance the readability and flexibility of code by use of the overloaded bitshift operator- for instance:
Code:

#include <iostream>

. . .

using namespace std;

. . .

cout << encoder1.Get() << endl;

Printf's really a C thing, but it is available in C++ if one needs fancier formatting or if one is allergic to the standard library for whatever reason. Then again, I can't speak for WindRiver/Diab- I still haven't gotten anything to run on that thing. It appears that they do have the simulator in this year's version (as opposed to last year where LabVIEW was the hands-down choice because of my team's large amount of code needing debugging and relative lack of robot), yet the installation of the C++ update seems to have failed probably due to the whole 32/64 bit thing. . .

byteit101 12-01-2012 15:57

Re: System.out.println help
 
it does work in windriver if you use cerr instead of cout (or if you reasign the streams)

EDIT: the C++ streams, that is


All times are GMT -5. The time now is 13:07.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi