If you're using getline after cin >> something
, you need to flush the newline out of the buffer in between.
#include <iostream>
#include <limits>
using namespace std;
int main() {
string t,p1,p2;
while(getline(cin, t))
{
cin>>p1;
cin>>p2;
cout<<"text is = "<<t<<"\np1 is = "<<p1<<"\np2 is = "<<p2<<endl;
cin.ignore (std::numeric_limits<std::streamsize>::max(), '\n'); // Dump everything until newline
}
return 0;
}
More here: https://stackoverflow.com/a/10553849/1938163