#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
相关推荐
SWAGGY..几秒前
【C++进阶】:(10)哈希表的原理与实现——从哈希函数到哈希桶码匠许师傅1 分钟前
【C++三方组件】redis-plus-plus:现代 Redis C++ 客户端LMT_Lanmantech2 分钟前
MATLAB合规管理:如何避免侵权赔偿和审计风险言乐612 分钟前
PythonLOLM自动生成复盘报告模型霸道流氓气质12 分钟前
HashiCorp Vault 与云 KMS 入门实战:动态密钥、SecretLeaseContainer 与 Java 集成完整指南wuminyu15 分钟前
stackChunkOop内部结构与GC屏障的配合工作原理剖析论文复现现场19 分钟前
DeepSeek V4.1 Flash 各平台价格怎么比?缓存、峰谷计费与 Python 成本计算xuxigifxfh19 分钟前
牛客:HJ21 简单密码小π军21 分钟前
C 和 C++ 是否都支持函数的重载?qq_4086068622 分钟前
确界的倒数性质证明