hello i started to learn input and output with files. but when i try to open a file it doesn't work. ive just took an example from the documentation. can someone tell me how to fix this ?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <iostream>
#include <fstream>
usingnamespace std;
int main ()
{
ofstream example ("ReadMe.txt",ios::app);
if(example.is_open())
{
example << "something";
example.close();
}
else
{cout<<"error"<<endl;}
system("pause");
return 0;
}
edit: he can't open the file.
maybe i have to save it on a special place or maybe i should tell him the location of the file
Yea I'd imagine readme.txt is bad. There is likely a readme.txt somewhere near the compiler with no write privelages. Try a different name and see what happens
It works for me without any changes. Try with the full path to the file, I expected it to be in the Debug folder(with executable) but it was created in a sub-folder. Executable is in C:\Users\Sean\Documents\Visual Studio 2010\Projects\Console App\Debug text file is in C:\Users\Sean\Documents\Visual Studio 2010\Projects\Console App\Console App\Debug.