Originally Posted By: NeoNeper
Now this correct?

Definitely not. The pointer returned by c_str() belongs to the hosting std::string, and it becomes invalid when calling a non const member function or upon the destructor call. The second your string goes out of scope, the returned pointer becomes invalid. Please read up on RAII and auto variables in C++.
Also, please use new style casts in C++, and don't cast away constness if you don't need to (and if you need to, keep in mind that altering any character of the returned string results in undefined behaviour!).

There simply is no way around making a copy of the string, though, and I want to stress this right now, allocating memory in one library and freeing it in another doesn't work. In debug builds, an assertion will be raised, in release builds all you get is a memory leak (actually, it does work, but you'd need control over the generation of both binaries, not just one. So just assume it doesn't work).


His words are wise, his face is beard.