Pergunta

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.

Foi útil?

Solução

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);
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top