#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
相关推荐
项目申报小狂人6 分钟前
中科院1区SCI-哲学命题优化算法Philosophical proposition optimizer-附Matlab免费代码2401_892000528 分钟前
Flutter for OpenHarmony 猫咪管家App实战 - 疫苗记录实现rit84324998 分钟前
基于光流场的 Demons 算法哈哈不让取名字9 分钟前
C++代码冗余消除heart_fly_in_sky10 分钟前
RK3576平台OpenCL GPU编程实战指南(Lesson 2)ghie909011 分钟前
基于C#实现俄罗斯方块游戏棱镜Coding12 分钟前
LeetCode-Hot100 27.合并两个有序链表燕山石头16 分钟前
java模拟Modbus-tcp从站lixzest18 分钟前
C++工程师的成长