boost之字符串算法库

来源:互联网 发布:淘宝优惠券名称写什么 编辑:程序博客网 时间:2024/05/22 06:43
#include <boost/algorithm/string.hpp>#include <string>#include <boost/algorithm/string_regex.hpp>#include <iostream>using namespace std;using namespace boost;bool is_exec_filename(string& filename){        return iends_with(filename,".exe") || iends_with(filename,".com");}int main(){      string str1(" hello world");     to_upper(str1);       string str2;   cout << to_lower_copy(str1)<<endl;    cout << str1 << endl;    trim(str1);    cout << str1 << endl;    string filename("a.exe");    cout<<"a.exe" << (is_exec_filename(filename) ? "is" : "is not") << "exe filename\n";    string text("thisistest");    cout <<(all(text, is_lower())?" is lower":" is not lower") << endl;    //字符串的裁剪    string str3(" hello world   ");    cout<<trim_left_copy(str3) << endl;    cout<<trim_right_copy(str3) << endl;    trim(str3);    cout << str3<<endl;    string phone("0086054487653421");    cout << trim_left_copy_if(phone,is_any_of("0")) << endl;    trim_if(phone,is_any_of("0"));    cout << phone << endl;            return 0;}

原创粉丝点击