Help with fstream file manipulation

Hey guys. I'm expirimenting with basic text file manipulation, like writing and reading text files, etc.. So far, this is what I've got.

1
2
3
4
5
6
7
8
9
10
  #include <iostream>
  #include <fstream>
  using namespace std;
  
  int main(){
      ofstream ofile;
      ofile.open("text.txt");
      ofile << "wrtiting to this file" << endl;
      ofile.close();
  }


Everything works fine, it creates a file called text.txt, and it writes to it just fine. The problem is when I write to it again, it doesn't append or insert text, it overwrites it.

I was just wondering how I could insert text into a text file, instead of overwriting it. Sorry if my english isn't great.

Thanks,
Ignacio Cabero
Yes, it does help a lot, thanks. Could you explain to me what exactly ios::out | ios::app
Does? I tend to remember things better if I know what it is exactly that they do.

Thank you,

Ignacio Cabero
Topic archived. No new replies allowed.