Hi.
Compilation of this program is OK :
---------------------
#include <string>
#include <fstream>
using namespace std ;
int main() {
ofstream myfile;
string FileName="Sample";
myfile.open((FileName).c_str());
myfile.close();
}
--------------------
but this one fails :
#include <string>
#include <fstream>
using namespace std ;
int main() {
ofstream myfile;
string FileName="Sample";
myfile.open(FileName);
myfile.close();
}
and the error message is:
no matching function for call to `std::basic_ofstream<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(FileName);" ?
What does the c_str() function ?
TIA
Erkson