标题:boost库简介之:字符串处理二

正文:
 3 正则表达式
 3.1 相关类:
  basic_regex
  regex
 3.2 定义文件
  #include <boost/regex.hpp>
 3.3 功能简介
  建立一个一定规则的regex表达式类对象,然会测试已有的子串是否与regex对象
 是否匹配,使用成员函数match来测试。
 3.4 使用举例
 
 3.5 其它
  regex用来处理正则表达式。
 
 4 符号序列分割容器
 4.1 相关类
  tokenizer
  token_iterator
  TokenizerFunc函数模板:
  char_separator
  escaped_list_separator
  offset_separator
 4.2 定义文件
  #include <boost/tokenize.hpp>
 4.3 功能简介
  用来分解一个字符串或其它的符号序列为子串,使用特定的分隔方法.默认的分隔方法为
 使用空格分隔一个字符串.
 4.4 使用举例
  UltraEdit10.10c + MS C/C++ Compiler12.00.8804 for 80x86 + win2k(sp5)+boost131测试通过。
  //示例代码取自boost库文档.
  // simple_example_1.cpp
  #include<iostream>
  #include<boost/tokenizer.hpp>
  #include<string>

  int main(){
     using namespace std;
     using namespace boost;
     string s = "This is,  a test";
     tokenizer<> tok(s);
     for(tokenizer<>::iterator beg=tok.begin(); beg!=tok.end();++beg){
         cout << *beg << "/n";
     }
  }


  // simple_example_2.cpp
  #include<iostream>
  #include<boost/tokenizer.hpp>
  #include<string>

  int main(){
     using namespace std;
     using namespace boost;
     string s = "Field 1,/"putting quotes around fields, allows commas/",Field 3";
     tokenizer<escaped_list_separator<char> > tok(s);
     for(tokenizer<escaped_list_separator<char> >::iterator beg=tok.begin(); beg!=tok.end();++beg){
         cout << *beg << "/n";
     }
  }


  // simple_example_3.cpp
  #include<iostream>
  #include<boost/tokenizer.hpp>
  #include<string>

  int main(){
     using namespace std;
     using namespace boost;
     string s = "12252001";
     int offsets[] = {2,2,4};
     offset_separator f(offsets, offsets+3);
     tokenizer<offset_separator> tok(s,f);
    for(tokenizer<offset_separator>::iterator beg=tok.begin(); beg!=tok.end();++beg){
        cout << *beg << "/n";
    }
 }


总结:
 关于字符串处理方面,还有一个spirit,我认为spirit使用文件解析容器,我也没看很清楚,所以有相关的
使用或者使用方法中文文档,请发一个:myemail_cn@tom.com
 未完,待续.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值