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.

有帮助吗?

解决方案

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);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top