Adding data to a txt on different line

I want to make a database of people but its over riding the text in the .txt. How would i do this ived tried my hardest to figure it out but i cant so all help is appreciated.

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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

void personCreator();

int main()
{

	for (;;)
	{
		system("cls");
		personCreator();
		cout << "Press Enter to restart or press 1 to exit" << endl;
		cin.get();
		char num = 1;
		if (num)
		{
			break;
		}
	}
		
	return 0;
}

void personCreator()
{
	string firstname, lastname, birthyear, birthmonth, date;
	cout << "Whats your firstname? "; getline(cin, firstname);
	cout << "Whats your lastname? "; getline(cin, lastname);
	cout << "Whats your birth year? "; getline(cin, birthyear);
	cout << "Whats your birth month? "; getline(cin, birthmonth);
	cout << "Whats your birth date? "; getline(cin, date);


	ofstream myfile;
	myfile.open(firstname + "_" + lastname + ".txt");
	myfile << "firstname: " << firstname << endl;
	myfile << "lastname: " << lastname << endl;
	myfile << "birthyear: " << birthyear << endl;
	myfile << "birthmonth: " << birthmonth << endl;
	myfile << "date: " << date;
	myfile.close();

	myfile.open("name.txt");
	myfile << firstname <<  "  " << lastname << endl;
	myfile.close();

}

Topic archived. No new replies allowed.