首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

getline有关问题

2013-01-28 
getline问题#include iostream.h#include stdlib.hvoid main(){ char s[5],s2[4] cin.getline(s,5)

getline问题
#include <iostream.h>
#include <stdlib.h>
void main()
{ char s[5],s2[4];
 cin.getline(s,5);
 cin.getline(s2,4);
 cout<<s<<endl<<s2<<endl; 
 system("pause");

}
为什么输入s串后就结束了而cin.getline(s2,4)忽略了;

[解决办法]
代码问问题吧,输入s别超过4个字符,就OK了。
[解决办法]
第一次 getline 出错了,第二次直接失败。
改成这样试试


cin.getline(s,5);
cin.clear(); // clear any error bit so that the next getline performs.
cin.getline(s2,4);

[解决办法]
我试了试,你的这种写法完全可以的,你说的情况是你第一次输入的字符数超过了4个,所以会直接打印第一个字符串而忽略第二个

热点排行