const char* c_str() const;
For compatibility with "older" code, including some C++ library routines, it is sometimes necessary to convert a string object into a pointer to a null-terminated character array ("C-style string"). This function does the conversion. For example, you might open a file stream with a user-specified file name:
string filename;
cout << "Enter file name: ";
cin >> filename;
ofstream outfile (filename.c_str());
outfile << "Data" << endl;
You may need to cast the const part out, but that should be easy enough.
Its amazing what you can find when you do a search for "
std::string"