|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
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. |
|
#2
|
||||
|
||||
|
Re: System.out.println help
Try this instead:
Code:
printf("Encoder1=%d", encoder1.Get());
|
|
#3
|
|||
|
|||
|
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());
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();
}
}
|
|
#4
|
|||
|
|||
|
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. |
|
#5
|
||||
|
||||
|
Re: System.out.println 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.
|
|
#6
|
||||
|
||||
|
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; |
|
#7
|
||||
|
||||
|
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 Last edited by byteit101 : 12-01-2012 at 16:14. Reason: clarifying |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|