C++如何连续输入多个可能含空格的字符串
可以尝试如下方案,亲测可行。
int main()
{
string s1,s2;
while(getline(cin,s1)&&getline(cin,s2))
{
cout<<s1<<endl;
cout<<s2<<endl;
}
return 0;
}以上是string类型的解决方案,下面是定义char数组如何处理的方法。
int main()
{
char s1[100],s2[100];
while(gets(s1)&&gets(s2))
{
cout<<s1<<endl;
cout<<s2<<endl;
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
posted on 2015-07-19 19:07 Tob__yuhong 阅读(959) 评论(0) 收藏 举报
浙公网安备 33010602011771号