Banking system

I've been trying to up my game by doing something a little more challenging by making a banking system. I just started this, but have a quick question. when I choose number 1 and add in a name it pops up just fine in the text document, but when I add another the name I just put in replaces the previous name.

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
  #include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;

void display(char& anwser);
void N_account(char& anwser,string & name);


int main()
{
	string name;
	char anwser;
	display(anwser);
	N_account(anwser,name);

}

void display(char& anwser)
{
	cout << setw(65) << "=================" << endl;
	cout << setw(65) << "Banking Managment" << endl;
	cout << setw(65) << "=================" << endl;
	cout << setw(60) << "1.New account" << endl;
	cout << setw(57) << "2.Withdraw" << endl;
	cout << setw(56) << "3.Deposit" << endl;
	cout << setw(65) << "4.Existing account" << endl;
	cout << setw(62) << "5.Close account" << endl;
	cin >> anwser;
}

void N_account(char& anwser,string & name)
{
	if (anwser == '1')
	{
			ofstream outfile;
			outfile.open("Accounts.txt");
			cout << "Enter in first and last name for new account:";
			cin.ignore();
			getline(cin, name);
			outfile << name;
			outfile.close();
		

	}
			

		
}
outfile.open("Accounts.txt"); will simply overwrite the old file.

If you want it to append to the outfile, you'd do something like
1
2
  std::ofstream ofs;
  ofs.open ("test.txt", std::ofstream::out | std::ofstream::app);

http://www.cplusplus.com/reference/fstream/ofstream/open/
Last edited on
Thank you! Another quick question however and I should be good. Now that I have that set I go into my text document to see the inputted words clumped together. I want them to have their own individual line. Any advice for that?
1
2
outfile << name;
outfile << '\n'; // newline 
Last edited on
Alright I should be good now thank you!
Topic archived. No new replies allowed.