printf
is a C function and expects a c-string, a char*
which is just a pointer to a place in memory where the contexts of the string reside. It assumes the string goes as far as the next '\0'
byte and will print the contents of the memory from the address passed as pointer up to that point (the next '\0'
).
std::string
is a class with several members. Apart from the actual string, it stores, for example, the current size. Besides, you did not pass a pointer to the string.
If you want to use std::string
with printf
, you'll have to call the c_str()
method on the string object. This method returns the content of the string object as char*
/ c-string and should always be used when using string objects with c-function that expect c-strings.
printf("* Debug: %s \n", myString.c_str());