boost库
来源:互联网 发布:刘宇昆 爱的算法pdf 编辑:程序博客网 时间:2024/04/26 01:08
vc++6.0环境下的使用正则表达式的一些总结
1,如何下载boost库?
官方下载地址http://www.boost.org/,这里我选择下载boost_1_34_0.zip
2,如何编译boost库中的正则表达式的子库?
如果要全编译boost得花一两个小时,如果只选择编译boost中的正则表达式的子库,大概10分钟,遵照以下几个步骤可以编译boost中的正则表达式的子库:
a) 开始 / 运行 / cmd
b) 输入 / Microsoft Visual Studio / VC98 / Bin / VCVARS32.BAT,回车
c) cd C:/boost_1_34_0/libs/regex/build // 转到boost中的正则表达式的子库的目录
d) 输入 nmake -fvc6.mak, 回车
经过以上步骤就能成功编译boost中的正则表达式的子库
3,如何设置vc6?
打开vc6,菜单 tools / options,在选项框内选择directories标签页
a) 在Show directories for 下选择 include files, 在Directories:下添加一个新的目录C:/BOOST_1_34_0
b) 在Show directories for 下选择 library files, 在Directories:下添加一个新的目录C:/boost_1_34_0/libs/regex/build/vc6
经过以上两步设置,就可以进行测试了,以下给出了示例
4,示例
// 示例1
#include <string>
#include <iostream>
#include <boost/regex.hpp>
int main() ...{
boost::regex reg("/d+");
boost::smatch m;
std::string str("my phone is 88886666 and age is 25");
std::string::const_iterator it = str.begin();
std::string::const_iterator end = str.end();
while(boost::regex_search(it, end, m, reg)) ...{
std::cout << m.str() << std::endl;
it = m[0].second;
}
boost::regex my_reg("My", boost::regex::icase | boost::regex::perl);
std::string res = boost::regex_replace(str, my_reg, "Solee's");
std::cout << res << std::endl;
return 0;
}
// 示例2
// 使用迭代器获取所有匹配
#include <boost/regex.hpp>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
class Show ...{
public:
template<class T>
void operator()(const T& t) ...{
cout << t.str() << endl;
}
};
int main(int argc, char* argv[])
...{
boost::regex reg("/d+");
string str("my num is 21314 and age is 26.");
boost::sregex_iterator it(str.begin(), str.end(), reg);
boost::sregex_iterator end;
for_each(it, end, Show());
return 0;
}
// 示例3
// 实现一个字符串分割函数split.
#include <string>
#include <iostream>
#include <vector>
#include <boost/regex.hpp>
#include <boost/shared_ptr.hpp>
using namespace std;
template<class Tchar>
boost::shared_ptr< vector<basic_string<Tchar> > > split(const basic_string<Tchar>& t,
const basic_string<Tchar>& tokenStr) ...{
boost::shared_ptr< vector<basic_string<Tchar> > > pRtn =
boost::shared_ptr< vector<basic_string<Tchar> > >(new vector<basic_string<Tchar> >);
static const boost::basic_regex<Tchar, boost::regex_traits<Tchar> > reg(tokenStr);
boost::regex_token_iterator<basic_string<Tchar>::const_iterator >
begin(t.begin(), t.end(), reg, -1);
boost::regex_token_iterator<basic_string<Tchar>::const_iterator > end;
while(begin != end) ...{
pRtn->push_back(*begin++);
}
return pRtn;
}
int main(int argc, char* argv[])
...{
string str("1,2,3,45,7");
string token(",");
boost::shared_ptr< vector<string> > pVec = split(str, token);
for(vector<string>::const_iterator it = pVec->begin();
it != pVec->end(); ++it) ...{
cout << *it << endl;
}
return 0;
}
#include <string>
#include <iostream>
#include <boost/regex.hpp>
int main() ...{
boost::regex reg("/d+");
boost::smatch m;
std::string str("my phone is 88886666 and age is 25");
std::string::const_iterator it = str.begin();
std::string::const_iterator end = str.end();
while(boost::regex_search(it, end, m, reg)) ...{
std::cout << m.str() << std::endl;
it = m[0].second;
}
boost::regex my_reg("My", boost::regex::icase | boost::regex::perl);
std::string res = boost::regex_replace(str, my_reg, "Solee's");
std::cout << res << std::endl;
return 0;
}
// 示例2
// 使用迭代器获取所有匹配
#include <boost/regex.hpp>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
class Show ...{
public:
template<class T>
void operator()(const T& t) ...{
cout << t.str() << endl;
}
};
int main(int argc, char* argv[])
...{
boost::regex reg("/d+");
string str("my num is 21314 and age is 26.");
boost::sregex_iterator it(str.begin(), str.end(), reg);
boost::sregex_iterator end;
for_each(it, end, Show());
return 0;
}
// 示例3
// 实现一个字符串分割函数split.
#include <string>
#include <iostream>
#include <vector>
#include <boost/regex.hpp>
#include <boost/shared_ptr.hpp>
using namespace std;
template<class Tchar>
boost::shared_ptr< vector<basic_string<Tchar> > > split(const basic_string<Tchar>& t,
const basic_string<Tchar>& tokenStr) ...{
boost::shared_ptr< vector<basic_string<Tchar> > > pRtn =
boost::shared_ptr< vector<basic_string<Tchar> > >(new vector<basic_string<Tchar> >);
static const boost::basic_regex<Tchar, boost::regex_traits<Tchar> > reg(tokenStr);
boost::regex_token_iterator<basic_string<Tchar>::const_iterator >
begin(t.begin(), t.end(), reg, -1);
boost::regex_token_iterator<basic_string<Tchar>::const_iterator > end;
while(begin != end) ...{
pRtn->push_back(*begin++);
}
return pRtn;
}
int main(int argc, char* argv[])
...{
string str("1,2,3,45,7");
string token(",");
boost::shared_ptr< vector<string> > pVec = split(str, token);
for(vector<string>::const_iterator it = pVec->begin();
it != pVec->end(); ++it) ...{
cout << *it << endl;
}
return 0;
}
- boost库
- Boost库
- Boost 库
- boost库
- Boost库
- Boost库
- boost库
- boost库
- Boost库
- boost库
- Boost-Boost库的编译
- 【Boost】C++ Boost库简介
- 【Boost】boost::assign库介绍
- 【Boost】boost::timer库用法与实例
- 【Boost】boost库的随机数的例子
- 【Boost】boost库中sleep方法详解
- Vs2010配置boost库,LINUX boost安装
- <Boost> VS2010使用Boost(C++库)
- 访问IIS元数据库失败
- 中移动研究院杨志强:终端开启移动互联网大门
- 十分钟让你看懂中国经济形势
- 个人发展思考
- 新闻切换技术
- boost库
- 手机的未来
- 解決NonUniqueObjectException異常及分析
- 【王若雄】张瑞敏:中国企业是“游击队”?
- 新劳动合同法实施前夜的尴尬
- odbc ado dao rdo 的相关评论
- SwingUtilities中invokeLater和invokeAndWait介绍(转载)
- 右键打不开盘符的解决方法
- Atlas学习手记系列(转)