因为毕设需要用到正则表达式的有关技术,故最近学习使用了boost库提供的正则表达式。以下是vc6.0下配置boost正则库的步骤。
1、下载boost库并解压,如D:\boost。
2、编译,因为只需要支持正则表达式就可以,因此只需要编译D:\boost\libs\regex\build目录下的文件。
打开cmd,进入D:\boost\libs\regex\build。
把VCVARS32.BAT文件用鼠标拖到打开的cmd窗口("D:\Program Files\Microsoft Visual Studio\VC98\Bin\VCVARS32.BAT"),然后回车。
输入命令“nmake -fvc6.mak”。
等待一会,此时D:\boost\libs\regex\build多了一个vc6的文件夹,里面是很多lib和dll文件。3、接下来配置VC6.0,使它编译时能找到正则库。
把刚才生成的vc6下的所有lib和dll文件拷贝到Visual Studio安装目录下的VC98\regex(regex是自己创建的目录,用于存放lib和dll文件)
然后打开vc6.0,选择“Tools->Options->Directories->Include files”,加入一行“D:\BOOST”
选择“Tools->Options->Directories->Library file”,加入一行“D:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\VC98\regex”
4、编写程序测试(以下代码从网上copy而来)
#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.str()<<endl; } else { cout<<"Error Input"<<endl; } return 0; } |
输入: select name from table
输出: str:select name from table
str:name
str:table
现在可以使用boost正则表达式库了。