Victor said:
Where is the guarantee that the pointer 'c_str()' returns in _not_ to some
temporary buffer that only contains characters up to and including the
first null char? Note that if the 'data()' of the std::string does _not_
contain a null char, the string _has_ to create a temporary buffer. So,
it is _most_ likely that the temporary buffer is created. And if it is,
there is no sense for the 'string' to copy anything there beyond the first
null character. Hence, the scenario where the 'string' truncates is as
equally plausible as the one where it doesn't.
That was not nitpicking. The standard (well - the draft, but I doubt
this has changed) says about c_str:
-1- Returns: A pointer to the initial element of an array of length
size() + 1 whose first size() elements equal the corresponding elements
of the string controlled by *this and whose last element is a null
character specified by charT().
Also, I doubt that many implementations will allocate a temporary
buffer. Most will just assure that the buffer always has room enough
for one extra character and place a null at size() whenever c_str is
called.
/Peter