-
- #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;
- }