However c_str() can create a new internal cstring that IS guaranteed to be null terminated.
In C++03, yes. In C++11, no.
Using that function is likely causing the extra memory usage.
I actually find that very unlikely. The popular implementations that I know of certainly don't. It's technically possible, yes (if he's using C++03), but it's unlikely he's working with an implementation that does so, just because most implementations (both C++03 and C++11) don't create a whole copy of the string when c_str() is called. As the OP stated in a later post: "It was me that was doing the extra memory allocation I falsely blammed c_str()"
If you want to keep the value returned from c_str() you will need to copy it yourself.
std::string mystr = "Hello world!";
const char *cstr = mystr.c_str();
char *copiedCStr = new char[mystr.size() + 1]; // no need to call an O(n) function when an O(1) function is available
Made a small improvement.
Edited by Cornstalks, 20 September 2012 - 11:16 PM.