本文共 1496 字,大约阅读时间需要 4 分钟。
From:
BOOST 正则表达式 在Visual Studio 2005 下(VC8)的安装
作者:覃学涵
1.下载boost
2.解压下载压缩包
boost_1_34_1.zip 解压到 e://boost_1_34_1/
我的VS 2005安装到 D:/Program Files/Microsoft Visual Studio 8/
把e://boost_1_34_1/整个目录复制到 D:/Program Files/Microsoft Visual Studio 8/VC/boost_1_34_1
3.在VC2005上编译安装
以下以我自己安装的VS2005的安装为例,说明编译安装过程
cmdcd D:/Program Files/Microsoft Visual Studio 8/VC/bin
vcvars32.bat
cd D:/Program Files/Microsoft Visual Studio 8/VC/boost_1_34_1/libs/regex/build/
nmake /f vc8.mak
nmake /f vc8.mak install
4.编译之后的LIB文件已经在 D:/Program Files/Microsoft Visual Studio 8/VC/libs 中,如图
但是这里有个生成错误,编译生成的LIB文件名称和编译版本不一致,这个小小的错误,需要自己手动修改,把文件的版本号“1_34”修改成 “1_34_1”,不然在VC2005开发环境中,编译器链接时会产生错误,错误如下:
Compiling...
RegHandler.cppGenerating Code...正在链接...LINK : fatal error LNK1104: 无法打开文件“libboost_regex-vc80-mt-gd-1_34_1.lib”正确的lib文件名应该如下:
5.编译安装完成之后,在VS 2005 上点击“工具--选项---项目和解决方案--VC++目录”然后在“显示以下内容的目录中”选择“包含文件”,添加一行,内容为“$(VCInstallDir)boost_1_34_1”如下图:
(上图最后一行就是boost_1_34_1的头文件的包含目录)
6.测试代码
#include "stdafx.h"
#include <cstdlib>#include <stdlib.h>#include <boost/regex.hpp>#include <string>#include <iostream>using namespace std;
using namespace boost;regex expression("^select ([a-zA-Z]*) from ([a-zA-Z]*)");
int main(int argc, char* argv[])
{ std::string in; cmatch what; cout << "enter test string" << endl; getline(cin,in); if(regex_match(in.c_str(), what, expression)) { for(int i=0;i<what.size();i++) cout<<"str :"<<what[i].str()<<endl; } else { cout<<"Error Input"<<endl; } return 0;}转载地址:http://oentb.baihongyu.com/