#include<iostream>
#include<bits/stdc++.h>
using namespace std;
vector<string> split(string s) {
int len = s.length();
int i(0);
string ans= "", temp;
vector<string> res;
while(i<len) {
temp = "";
while(i<len&&s[i]==' ') {i++;}
while(i<len&&s[i]!=' ') {
temp += s[i++];
}
res.push_back(temp);
}
return res;
}
int main(int argc, char** argv) {
string s = "dog cat cat dog";
vector<string> res;
res = split(s);
cout<<"字符串单词数量 "<<res.size()<<"------"<<endl;
for(auto i:res) {
cout<<i<<endl;
}
return 0;
}
10-17
651
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
05-12
821
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
06-19
246
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)