Question

In C/C++, is there a way to write my function so that I can use format codes to print information easier? The function draws text to the screen with SDL, so I can't pass in a C++ string; it has to be a char array.

Was it helpful?

Solution

Firstly, you can convert a c++ string to a char array using myString.c_str().

Also, you can use sprintf() with format codes to produce a string. Then you can draw that string using SDL. For example:

char myString[1024];
sprintf(myString, "Hello my name is %s", "foo");
draw_using_SDL(myString);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top