what changing i can made in following code that all the previous entered data remain in file even i entered other data!!! means i run program many time so it should contain all data how many times i entered!!!please help...
#include<iostream>
#include<fstream>
#include<stdio.h>
#include<string>
using namespace std;
void write()
{
string name;
int phone_no;
int id;
string address;
string car_name;
string car_color;
cout << "\n Enter name:";
cin >> name;
cout << "\n Enter phone:";
cin >> phone_no;
cout << "\n Enter id:";
cin >> id;
cout << "\n Enter address:";
cin >> address;
cout << "\n Enter car name:";
cin >> car_name;
cout << "\n Enter car model:";
cin >> car_color;
ofstream write_file("car.txt");
write_file << name << "\n" << phone_no << "\<<id<<"\n;
write_file << address << "\n<<car_name<<"\n"<<car_color<<"\n";
cout << "File written\n";
}
void read()
{
string name;
int phone_no;
int id;
string address;
string car_name;
string car_color;
fstream read_file("car.txt");
read_file >> name >> phone_no >> id >> address >> car_name >> car_color;;
cout << name << endl << phone_no << endl << id << endl << address << endl;
cout << car_name << car_color << endl;
}
int main()
{
int choice;
do
{
cout << "\n*********** Main Menu *************";
cout << "\n 1: -Do you want to write\n";
cout << "\n 2: -Do you read\n";
cout << "\n 3: -exit\n";
cout << "\n Enter your choice no :";
cin >> choice;
switch(choice)
{
case 1:
write();
break;
case 2:
read();
break;
case 3:
exit(0);
break;
}
} while(choice < 3);
return 0;
system("pause");
}