xjhjtz0320 @ 2024-11-29 19:25:19
if(zfccz=="in"){
cout<<"请输入字符串";
getline(cin,strzfc);
cout<<123;
}
by ikunTLE @ 2024-11-29 19:26:50
@xjhjtz0320 疑似换行被吃掉了
by yukimianyan @ 2024-11-29 19:27:26
试一下 getline(cin>>ws,strzfc);
by pies_0x @ 2024-11-29 19:28:03
@xjhjtz0320 清空缓冲区,cin.sync()
by _hsk121212_ @ 2024-11-29 19:28:17
@xjhjtz0320应该是 getline读取到了缓冲区的字符?
by _liangshuai_ @ 2024-11-29 19:29:15
@xjhjtz0320 有可能读入了换行符,cin.ignore(1000,'\n')
滤一下换行符
by pies_0x @ 2024-11-29 19:29:56
@xjhjtz0320 可以了,完整代码如下:
if(zfccz=="in"){
cout<<"请输入字符串";
cin.sync();
getline(cin,strzfc);
cout<<123;
}
by chengjindong @ 2024-11-29 19:30:25
getline读到了末尾的换行
by pies_0x @ 2024-11-29 19:34:07
by xjhjtz0320 @ 2024-11-29 20:05:18
已经好了,感谢各位大佬