正文: 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使用文件解析容器,我也没看很清楚,所以有相关的 使用或者使用方法中文文档,请发一个:[email protected] 未完,待续.

|