【发布时间】:2019-01-14 04:23:15
【问题描述】:
代码部分:
int t;
cout<<"Enter a no.";
cin>>t;
while(t--){
cout<<"Enter a string :"<<endl;
string str;
cin.ignore();
getline(cin,str);
cout<<"You entered :"<<str<<endl<<endl;
}
Enter a no. 3
Enter a string :
It is working
You entered :It is working
Enter a string :
It is working
You entered :t is working
Enter a string :
It is working
You entered :t is working
为什么在第二次迭代中跳过第一个字符。欢迎任何帮助。
【问题讨论】:
-
如果我删除 cin.ignore() 则输入不正确,所以我应该怎么做才能在每次迭代中输入。
标签: getline