I try to write a simple program that writes something in a file like I saw in the input/output tutorial from your site.
Everything is compiling nicely but happens nothing with the file.
I thing that the program just doesn't know where to look for the file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
*
#include <iostream>
#include <fstream>
usingnamespace std;
int main () {
ofstream myfile ("exercise.txt");
if (myfile.is_open())
{
myfile << "This is a line.\n";
myfile << "This is another line.\n";
myfile.close();
}
else cout << "Unable to open file";
cin.get();
return 0;
}
#include <iostream>
#include <fstream>
usingnamespace std;
int main () {
ofstream myfile ("exercise.txt");
if (myfile.is_open())
{
myfile << "This is a line.\n";
myfile << "This is another line.\n";
myfile << flush;
}
else cout << "Unable to open file";
myfile.close();
cin.get();
return 0;
}