How do I append 3 more integers in a text file?

I'm doing my homework for computer science class.
I'm stuck on this particular problem.
It's asking us to input 3 integers which will write to text.txt
When finished, I need to open text.txt to check if it contains the integers.
While it's open, I need to add 3 more integers, total of 6 integers in the file.

This is what I have so far..

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
	int int1, int2, int3;
	ofstream outFile;
	outFile.open("Data.txt");



	if (outFile.fail())
	{
		cout << "File did not open!\n";

		exit(1);

	}

	cout << "Please enter 3 numbers. \n";
	cin >> int1 >> int2 >> int3;
	outFile << int1 << endl << int2 << endl << int3;
	
	outFile.close();
	return (0);


When I use this code again, it just overwrites the file instead of adding 3 more integers. Please help me.

Thank you in advance.
https://en.cppreference.com/w/cpp/io/ios_base/openmode
You open the file in append mode.
For an example of opening a file in append mode:

http://www.cplusplus.com/reference/fstream/ofstream/open/
When you get the append function to work, try running the program with input "1 2 3" and then run it again with input "4 5 6" I think you'll find that Data.txt then looks like this:
1
2
34
5
6

Can you tell what's wrong?
Topic archived. No new replies allowed.