#include <iostream>
#include <fstream>
usingnamespace std;
int main () {
ofstream myfile;
myfile.open ("example.txt");
myfile << "Writing this to a file.\n";
myfile.close();
return 0;
}
That's exactly right. However, I suggest between opening the file and writing to it, you use std::ofstream::fail() to check that the file has opened correctly.