Brain.Screen.print(std::string) not working

I have a function that prints out the temperature of a motor:

void printTemp(int lineNum, std::string motorName, motor motorObject) {
  Brain.Screen.setCursor(lineNum, 1);
  Brain.Screen.print(motorName);
  Brain.Screen.print("%f", motorObject.temperature(celsius));
}

I call it using printTemp(1, "Right Motor 1: ", rightMotorA);

I always seem to be getting an error:

/Applications/VEXcode Pro V5.app/Contents/Resources/sdk/vexv5/include/vex_brain.h:256:28: error: cannot convert ‘std::basic_string’ to ‘int’ without a conversion operator
print( “%d”, (int)value );
^~~~~~~~~~
src/main.cpp:95:16: note: in instantiation of function template specialization ‘vex::brain::lcd::print<std::basic_string >’ requested here
Brain.Screen.print(motorName);
^
1 error generated.
make: *** [build/src/main.o] Error 1
[error]: make process closed with exit code : 2

Brain.Screen.print() does not like std::string for some reason. You can fix it by converting it to a C-style string (const char*):

Brain.Screen.print(motorName.c_str());
5 Likes

We avoided any reliance on the standard library in the VEX sdk for portability reasons (ie. it makes it much easier to port to platforms such as IQ generation 1 which do not have the available resources).

5 Likes