Reputation: 595
I'm facing some issues in taking input in C++ after using getline
. Following is the piece of code:
cin>>n;
vector<string>v(n);
string s, type;
bool reversed;
getline(cin, s);
for(int i=0;i<n;i++) {
getline(cin, s);
v[i]=s;
}
cin>>key;
cin>>reversed;
cin>>type;
for the following input --
3
92 022
82 12
77 13
2 true digital
What I need is the following lines to be taken as string with spaces--
92 022
82 12
77 13
which I'm able to, but the value of reversed is always 0 and type is always blank. Please help what I'm doing wrong in taking input?
I also had to use getline
once before for loop to take the input for "n" string correctly. How to avoid that?
Upvotes: 0
Views: 93