Hi,
Would anyone know how to avoid using c_str() when reading
text from a file?
Thank You,
Paul
Hi,
Would anyone know how to avoid using c_str() when reading
text from a file?
Thank You,
Paul
If we are talking about the same thing, c_str() is the member function (method) of the class string. The function is to get the pointer to a c-like string or in other words a character array termintated by the null character. c_str() can be used for retrieval purposes but not modification.
Example
string s;
char buffer[80];
s = "what's up people";
strcpy(buffer, s.c_str() );
to copy into it instead you would do this...
buffer[1000] = {"lskfjlsjflsdlfslf"};
string s;
s = buffer;
basic_string::c_str
const E *c_str() const;
The member function returns a pointer to a nonmodifiable C string constructed by adding a terminating null element (E(0)) to the controlled sequence. Calling any non-const member function for *this can invalidate the pointer.
--------------------------------------------------------------------------------