file appending

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>
using namespace 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
Last edited on
What does it do?
the output is error
and it is supposed to append 'something' to the ReadMe.txt file
Last edited on
Oooh, file name is an issue I think
you think i named the readme.txt wrong or ?
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
Ok so after looking at VS2010, a ReadMe.txt gets created for each project you make. I didnt look at my code::blocks but I imagine its similar
does it work for you ? maybe its just the compiler
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.
Topic archived. No new replies allowed.