Quote:
Originally Posted by zero0x
eu, i am sorry, i didnt realize that we're talking about C (not c++)
sprintf is a C function, it cannot use a C++ string object as it's output, even in C++. C++ strings cast to
const char *, not
char *, and that's an important distinction -- it's const because you're
not supposed to write to it. There's no way to overload accesses to a pointer -- if you do, it's no longer a pointer -- so it'll never know to allocate memory to hold what you're writing to it. For example, if it's holding "Hello", and you write "hello12345676" to it, the "12345676" bit might overwrite class members or anything else nearby in the heap.
They will work as inputs, as long as you use
object.c_str() instead of just
object.