#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
相关推荐
凉茶钱1 分钟前
【C++】string 常用函数详解梦帮科技4 分钟前
【3.0修订版】创世与节点工程:genesis.json 与 node.toml 解剖Wang's Blog11 分钟前
Java框架 SpringCloud 快速入门: 从服务拆分到注册中心的落地路线影视飓风TIM12 分钟前
Linux 进程虚拟地址空间详解如何原谅奋力过但无声16 分钟前
【灵神高频面试题合集21-25】动态规划(下)释厄62326 分钟前
学术引用本体论——WorkBuddy 学术科学文化三违反可乐鸡翅yeah_27 分钟前
hls.js 缓冲区参数 maxBufferLength、maxBufferSize 通俗讲解与业务调参梦帮科技27 分钟前
【3.0修订版】 RNS 代币架构:ERC20 五件套扩展与六钱包分配Wang's Blog29 分钟前
Java框架 SpringCloud 快速入门: 全局过滤器(GlobalFilter)自定义鉴权白山编程大哥32 分钟前
C语言篇:可变参数函数