#include
#include
#include
using namespace std;
int main()
{
vector svec;
string s1("dog cat cat fish");
for (unsigned int i = 0; i != s1.size(); ++i)
{
string s3 = "";
while (s1[i] != ' '&&i < s1.size())
{
s3 += s1[i];
++i;
}
svec.push_back(s3);
while (s1[i] == ' '&&i < s1.size())
{
s3.clear();
}
}
for (vector<string>::iterator i = svec.begin(); i != svec.end(); ++i)
{
cout << *i << endl;
}
system("pause");
return 0;
}
我想要分别提取出string:s1中的“dog”,“cat”,“cat”,“fish”;把空格去掉,把这些字符放置在vector中。为什么在vs编程时无法通过,没有数据输出??求解释