c++中的getline函数的问题
#include<iostream>
#include<string>
#include<cstdlib>
using namespace std;
int main (){
string name1;
string name2;
cout<<"Enter your first name: "<<endl;
getline(cin,name1,'\n');
cout<<"Enter your last name: ";
getline(cin,name2,'\n');
cout<<"Here's the information in a single string: "<<name2<<", "<<name1<<endl;
return 0;
}
运行的结果是
Enter your first name:
123
456
Enter your last name:
789
Here's the information in a single string: 456, 123
Press any key to continue
怎么会是这样子的呢?
在第一个getline 后怎么会要输入两行呢?,而name2又变成了456,