Boost字符串分割split

   boost中的split分割函数使用:

#include<iostream>
#include<fstream>
#include<vector>
#include<string>
#include<boost/algorithm/string/classification.hpp>
#include<boost/algorithm/string/split.hpp>
using namespace std;
using namespace boost;
int main(){
    ifstream in("1125.txt",ios::in);
    string s;
    getline(in,s);
    cout<<s<<endl;
    vector<string> vec;
    split(vec,s,is_any_of("|"));
    for(vector<string>::iterator it=vec.begin();it!=vec.end();it++){
        if(*it!="")
            cout<<*it<<endl;
    }
    return 0;
}

假设1125.txt中内容为hello||world

则程序输出为:

hello||world
hello
world

你可能感兴趣的:(Boost字符串分割split)