首页 > 编程语言 > 详细

c++给定字符分割

时间:2020-01-12 10:51:34      阅读:68      评论:0      收藏:0      [点我收藏+]
 1 //c++给定字符分割
 2 #include<iostream>
 3 #include<vector>
 4 #include<string.h>
 5 using namespace std;
 6 int main()
 7 {
 8     /* 最终把要分割的字符串根据给定分隔符划分为多个短的字符串*/
 9     vector<string> v;
10     string sa="he**llo,wo,r,ld*aaa";
11     char ch[100];
12     strcpy(ch,sa.c_str());
13     char fgf[]="* ,";
14     char *p;
15     p=strtok(ch,fgf);
16     while(p)
17     {
18         string zfc=p;
19         v.push_back(zfc);
20         p=strtok(NULL,fgf);
21     }
22     for(int i=0;i<v.size();i++)
23     {
24         cout<<v[i]<<endl;
25     }
26 }

但是要注意,给定的分隔符必须是char数组类型。

c++给定字符分割

原文:https://www.cnblogs.com/dayq/p/12182086.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!