Boost字符串分割split

来源:互联网 发布:条形码绑定数据库 编辑:程序博客网 时间:2024/04/29 15:29

   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

原创粉丝点击