#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
相关推荐
土司大王34 分钟前
LeetCode hot100——35.搜索插入位置:Java 二分模板、左闭右开区间与插入点分析微三云生态系统架构师-彭丹1 小时前
远方好物S2B2C系统架构:一级分销与保证金托管的合规技术实现言乐61 小时前
Python加速器4跨境网络加速器土司大王1 小时前
LeetCode hot100——34.在排序数组中查找元素的第一个和最后一个位置:Java 二分模板、边界分析金金计较.1 小时前
Go语言-3张小凡vip2 小时前
python--爬虫--经验积累的遇到的坑罗西的思考2 小时前
机器人模型(WM / WAM / VLA)综合分析与对比:从「看」到「想」再到「做」Wang's Blog3 小时前
Java框架快速入门: Spring Security+OAuth2之云服务集成与多因子认证设计门思科技3 小时前
LoRaWAN 网络容量估算:一个 SX1302 网关到底能带多少设备大草原的小灰灰3 小时前
Python基础语法