#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;
}
字符串分割单词C++
IRON_MAN_LEVEL12023-11-10 20:24
相关推荐
weixin_421922693 分钟前
模板代码性能测试Red丶哞8 分钟前
内网自建Postfix使用Python发送邮件静心观复10 分钟前
使用 new 关键字和 Java 反射创建对象的区别Liu6288814 分钟前
C++中的模板方法模式qq_3349031521 分钟前
高性能网络协议栈光电笑映23 分钟前
STL 源码解剖系列:map/set 的底层复用与红黑树封装老四啊laosi24 分钟前
[C++进阶] 19. map && set的使用阿贵---25 分钟前
模板编译期循环展开2601_9540236625 分钟前
Beyond the Hype: Deconstructing the 2025 High-Performance Stack for Agencies沉鱼.4425 分钟前
滑动窗口问题