int main()
{
int choice;
const int SIZE =41;
char name[SIZE],address[SIZE],hpnum[SIZE],opnum[SIZE],mpnum[SIZE];
double icnum ;
cout <<" \n\n\n\n ---------------1. Save the information--------------"<<endl;
cout <<" ---------------2. Retrieve the information----------"<<endl;
cout <<" ---------------3. Exit------------------------------"<<endl;
cout <<"\n\nPlease enter your choice : <1>,<2>,<3> ";
cin >> choice;
cin.ignore();
if (choice ==1)
{
cout <<"\nEnter your friend's name :";
cin.getline(name,SIZE);
cout <<name<<endl;
cout <<"Please enter your friend's IC number :";
cin >>icnum;
cout <<setprecision(12)<<icnum;
cin.ignore();
cout<<"\nPlease enter your friends's Address :";
cin.getline(address,SIZE);
cout<<address;
cout <<"\nPlease enter your friend's home phone number :";
cin >>hpnum;
cout <<"\nPlease enter your friend's office phone number :";
cin >>opnum;
cout <<"\nPlease enter your friend's mobile phone number :";
cin >>mpnum;
if (choice == 2)
{
ifstream input ;
input.open("Demo.txt");
input >> name;
cout <<name<<endl;
input >> name;
cout <<name<<endl;
input >> name;
cout <<name<<endl;
input >> name;
cout <<name<<endl;
input >> name;
cout <<name<<endl;
input >> name;
cout <<name<<endl;
input.close();
}
getch();
return 0;
}
Firstly,i type the "1" button to answered the question ,which is later print out in the Demo text file like :
low nan zhi
8899776655
2334,Taman Berapi ,tangganu
8988
554
656
After that i execute the program again and type "2" to test if the info could be retrieve.This is the result i got :
low
nan
zhi
8899776655
2334,Taman
Berapi
How could i retrieve the information with the right sequences just exactly looks like the info in the text file ?
low nan zhi
8899776655
2334,Taman Berapi ,tangganu
8988
554
656