Ok so im trying to write a simple program that stores user imput and I'm having problems with the getline command. The code is as follows:
When I run the program, it works until it asks me if I want to repeat the operation. If I choose to do so, it will cout Imput#1 without allowing me to input any information, and skips to Input#2 but this time allowing to type something.Code:#include <iostream> #include <ostream> #include <string> #include <fstream> using namespace std; int main() { int x; string p1; ofstream Prod ( "Example.txt", ios::app ); do { cout<<"Input#1 "<<"\n"; getline (cin, p1); Prod<< p1 <<"\n"; cout<<"Input#2"<<"\n"; cin>> p1; Prod<< p1 <<"\n"; cin.ignore(); cout<<"Input#3"<<"\n"; cin>> p1; Prod<< p1 <<"\n"; cin.ignore(); p1 = (); cout<<"Repeat operation?:\n"; cout<<"1) Yes\n"; cout<<"2) No\n"; cin>> x; } while (x != 2); cin.get(); }
Any help is much appreciated! Thank you.



LinkBack URL
About LinkBacks


