为什么下面代码运行时好像跳不出循环似的。解决方案
为什么下面代码运行时好像跳不出循环似的。。
#include <iostream>
#include <string>
using std::cin;
using std::cout;
using std::endl;
using std::string;
int main()
{
string s,temp;
while(cin>>temp)
s += temp+" ";
s[s.size()-1]='\0';
cout<<s<<endl;
return 0;
}
------解决方案--------------------
Ctrl+Z + 回车
------解决方案--------------------
------解决方案--------------------
自己约定一个结束标志:
while(cin>>temp&&temp != "END")
s += temp+" ";
输入END结束。
#include <iostream>
#include <string>
using std::cin;
using std::cout;
using std::endl;
using std::string;
int main()
{
string s,temp;
while(cin>>temp)
s += temp+" ";
s[s.size()-1]='\0';
cout<<s<<endl;
return 0;
}
------解决方案--------------------
Ctrl+Z + 回车
------解决方案--------------------
------解决方案--------------------
自己约定一个结束标志:
while(cin>>temp&&temp != "END")
s += temp+" ";
输入END结束。