#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 小时前
leetcode542 01矩阵原来是猿1 小时前
理解 C++ 哈希表的原理与工程实践雪的季节2 小时前
Qt 自定义表头wu_ye_m2 小时前
学习c语言第34天 用函数每次输出+1,链式访问,int和voidC137的本贾尼2 小时前
JDBC 编程:用 Java 连接 MySQLAI视觉网奇2 小时前
three-bvh-csg glb分割牢姐与蒯2 小时前
c++数据结构之c++11(二)z200509302 小时前
【linux学习】深入理解 Linux 进程间通信:管道的艺术与实现星马梦缘2 小时前
算法设计与分析 作业三 答案与解析lcj25112 小时前
【stack、queue、deque、priority_queue】C++ 栈 / 队列 / 优先级队列全解析!手撕实现 + 二叉树层序遍历(附源码)