std::ofstream file(filename); // open file for writing
Unfortunately, before C++11, the file stream classes did not provide a constructor taking a string
as argument. So, before C++11, you had to write:
std::ofstream file(filename.c_str()); // open file for writing before C++11
After this declaration, it is determined whether the stream is in a good state:
if (! file) {
...
}