Why can't I use multiple getlines()
C++ Code:
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
using namespace std;
int main()
{
int choice=0;
while(choice<6)
{
cout << "1. Add Entry Name, age and address" << endl;
cout << "2. Edit Information" << endl;
cout << "3. Delete Information" << endl;
cout << "4. View" << endl;
cout << "5. Exit program" << endl;
cout << "Please pick a choice" << endl;
cin >> choice;
if(choice==1)
{
cout << "You chose to add an entry" << endl;
cout << "Please enter your full name:" << endl;
string name;
getline(cin,nam e);
cout << "Please enter your age:" << endl;
string age;
getline(cin,age );
cout << "Please enter your address:" << endl;
string address;
getline(cin, address);
ofstream myfile;
myfile.open("C: \\users\\APAdal ian15\\Desktop\ \User_Informati on.txt");
cout <<"Creating new file... Please wait..." << endl;
myfile << name << endl;
myfile << age << endl;
myfile << address << endl;
myfile.close();
}
system("PAUSE") ;
return 0;
}
}
C++ Code:
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
using namespace std;
int main()
{
int choice=0;
while(choice<6)
{
cout << "1. Add Entry Name, age and address" << endl;
cout << "2. Edit Information" << endl;
cout << "3. Delete Information" << endl;
cout << "4. View" << endl;
cout << "5. Exit program" << endl;
cout << "Please pick a choice" << endl;
cin >> choice;
if(choice==1)
{
cout << "You chose to add an entry" << endl;
cout << "Please enter your full name:" << endl;
string name;
getline(cin,nam e);
cout << "Please enter your age:" << endl;
string age;
getline(cin,age );
cout << "Please enter your address:" << endl;
string address;
getline(cin, address);
ofstream myfile;
myfile.open("C: \\users\\APAdal ian15\\Desktop\ \User_Informati on.txt");
cout <<"Creating new file... Please wait..." << endl;
myfile << name << endl;
myfile << age << endl;
myfile << address << endl;
myfile.close();
}
system("PAUSE") ;
return 0;
}
}
Comment