c++ 字符串切割
程序员文章站
2022-07-14 11:57:52
...
#include <stdio.h>
#include<iostream>
#include<vector>
#include <algorithm>
using namespace std;
int main(){
string s1="abc bdc dc";
const char *sep = " "; //可按多个字符来分割
char *p;
char *st= (char*)s1.data();
vector<string> res;
p = strtok(st, sep);
while(p){
string temp=p;
res.push_back(temp);
p = strtok(NULL, sep);
}
int i;
for(i=0;i<res.size();i++)//反转
{
reverse(res[i].begin(),res[i].end());
cout<<res[i]<<endl;
}
return 0;
}
上一篇: C++ getline函数切割字符串
下一篇: C++字符串切割