output file is overwrited

Hi everybody. This is my first post.
For the customer function, i have tried to output to text file and data are overwrite each time i run the program. i have no idea how to save the data in a series which i want.

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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

void customer(int id, string name, string occ, int num)
     {
           cout<<"Enter customer id:";
           cin>>id;
           cout<<"Enter customer name:"; 
           cin>>name;
           cout<<"Enter customer occupation:"; 
           cin>>occ;
           cout<<"Enter customer phone number:";
           cin>>num;
           ofstream outfile ("customer.txt");
           outfile<<id<<name<<occ<<num;
     }

int room(int room_id, string type, int floor)
     {
              cout<<"Enter room id:";
              cin>>room_id;
              cout<<"Enter room type:";
              cin>>type;
              cout<<"Enter room floor number:";
              cin>>floor;
     }
int rental(int cust_id, int room_id, int arriv, int depart )
    {
              cout<<"Enter customer id:";
              cin>>cust_id; 
              cout<<"Enter room id:";
              cin>>room_id; 
              cout<<"arrival date ddmmyy:";
              cin>>arriv;
              cout<<"departure date ddmmyy:";
              cin>>depart;
    }
     
int main()
    {      
          
          int choice; int x; string y; string z; int a;
          int b; string c; int d; int e; int f; int g; int h;
          cout<<"****Main Menu****"<<endl;
          cout<<"customer_____1"<<endl;
          cout<<"room_________2"<<endl;
          cout<<"rental_______3"<<endl;
          cout<<"exit_________0"<<endl;
          cout<<"Enter your choice";
          cin>>choice;
         switch (choice)
          {
           case 1:
           customer( x, y, z, a);
           break;          
           case 2:
           room(b, c, d);
           break;
           case 3:
           rental(e, f, g, h);
           break;
           case 0:
           exit(1);
           default:
           cout<<"wrong choice"<<endl;
           }
           main();
          
         system("pause");
         
        }
Open your file with the flags as std::ios::out | std::ios::app.
Hope this helps.
Topic archived. No new replies allowed.