|
运行了一个在一行字符串中按空格拆分单词的程序,但在输入中跳不出while的循环,
在网上找了好几种方法,Ctrl+z,Ctrl+d都不行。。。哪位大佬帮我看看,跪谢!!!
下面是源码:
#include<iostream>
#include<vector>
#include<iomanip>
#include<string>
#include<math.h>
#include<cctype>
vector<string> split(const string& s)
{
vector<string> ret;
typedef string::size_type string_size;
string_size i = 0;
while (i != s.size())
{
while (i != s.size() && isspace(s))
i++;
string_size j = i;
while (j == s.size() && !isspace(s[j]))
{
ret.push_back(s.substr(i, j - 1));
i = j;
}
}
return ret;
}
int main()
{
string s;
while (getline(cin, s)) //这里在调试的时候总是跳不出循环。。。
{
vector<string> v = split(s);
for (vector<string>::size_type i = 0; i != v.size(); ++i)
cout << v << endl;
}
return 0;
}
|
上一篇: 求助 怎么编写自动查找串口连接的硬件设备的方法下一篇: 构造函数初始化属性与直接初始化属性区别?(代码在里面)
|