Hi.
Compilation of this program is OK :
---------------------
#include <string>
#include <fstream>
using namespace std ;
int main() {
ofstream myfile;
string FileName="Sampl e";
myfile.open((Fi leName).c_str() );
myfile.close();
}
--------------------
but this one fails :
#include <string>
#include <fstream>
using namespace std ;
int main() {
ofstream myfile;
string FileName="Sampl e";
myfile.open(Fil eName);
myfile.close();
}
and the error message is:
no matching function for call to `std::basic_ofs tream<char
------------------------
I would like to understand what is c_str() function for.
Isn't my string the "const char * filename" that requires the open function
void open ( const char * filename, openmode mode = out | trunc ) ?
Is there a way to avoid c(str() it and only write "myfile.open(Fi leName);" ?
What does the c_str() function ?
TIA
Erkson