Print a String Variable

In VEXcode, how do I print a variable in string form? I am drawing a map of the field on the screen for auton selection purposes. I need to define a string variable in the function declaration, use it to print to the brain screen, and define the variable where I call my function.
I have a function like this:

void drawMap (std::sting desc){
    Brain.Screen.PrintAt(240, 40, [print the variable in here somewhere]);

}


int main(){
    drawMap("I am writing a description here. This is what should be printed on the brain");
}
Brain.Screen.PrintAt(240, 40, "someString will be printed here: %s", someString);

Take a look at how to use printf() for more context.

2 Likes

Capture

I still get the error

It will be difficult to help you further without seeing the rest of your code.

You are trying to pass an std::string which is a class. It can only accept char * (a character array). std::string does have a function to get it as a char array: .c_str(). So your code should look like this…

Brain.Screen.printAt(240, 40, "Description: %s", desc.c_str());
3 Likes

This didn’t fix it. Capture

In cpp there is the idea of function overloading, where two function can have the same name, but different variables. The Screen class has two functions…

printAt( int32_t x, int32_t y, const char *format, ... );
printAt( int32_t x, int32_t y, bool bOpaque, const char *format, ... );

The problem is that it is unable to decide which function you are trying to use, since it can convert the char * to a bool and then the second char *, from the string, can work as the format parameter.

To fix this just add a bool to tell it you want to use the second function…

Brain.Screen.printAt(240, 40, false, "Description: %s", desc.c_str());
3 Likes