C++常用字符串分割方法实例汇总

2020-01-06 20:22:13王振洲

最近发现boost里面有自带的split的函数,如果用boost的话,还是直接用split的好,这里就不多说了,代码如下:


#include <iostream>
#include <string>
#include <vector>
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/split.hpp>
 
using namespace std;
 
int main()
{
 string s = "sss/ddd,ggg";
 vector<string> vStr;
 boost::split( vStr, s, boost::is_any_of( ",/" ), boost::token_compress_on );
 for( vector<string>::iterator it = vStr.begin(); it != vStr.end(); ++ it )
  cout << *it << endl;
 return 0;
}

希望本文所述对大家的C++程序设计有所帮助。


注:相关教程知识阅读请移步到C++教程频道。