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

王朝other·作者佚名  2006-01-09
宽屏版  字体: |||超大  

正文:

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

未完,待续.

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有