vendredi 30 novembre 2018

C++ ofstream can't open file from variable name (not even after using c_str())

In my code I am trying to create a file and write to it.

std::ofstream saveFile("file.txt");
ofstream << "test" << endl;

Works perfect! But,

std::string fileName = "file.txt"
std::ofstream saveFile(filename.c_str());
ofstream << "test" << endl;

I've tried with and without c_str(), with no luck. There are no errors. But ofstream.good() returns false.

Aucun commentaire:

Enregistrer un commentaire