Originally Posted by
kamitsuna
Oh i understand, i was close. Not sure i understand what c_str() is though.
c_str() is what formats the string of fout?
Hmm, looks like ofstream takes a const char*, not a string.
Code:
char fname[]="myfile.txt"; // C-string ("fname" would be a char*)
string fname="myfile.txt"; // C++ string ("fname" is not a char*)
But .c_str() is a string.method that converts the C++ string to a C string. So another example:
Code:
string fname="myfile.txt";
ofstream(fname.c_str());
Without that, ofstream will throw an error.