轉自:http://jinyun2012.blog.sohu.com/155691639.html
下載boost最新庫
安裝:
1、打開vs2005在菜單tools中選擇Visual Studio 2005 Command Prompt,打開已配置好環境的命令行。
2、進入目錄boost_1_34_1\libs\regex\build,
編譯文件:nmake -f vc8.mak
安裝(將編譯好的文件復制到vs2005的特定目錄下):nmake -f vc8.mak install
刪除臨時文件:nmake -f vc8.mak clean
3、Tools->Options->Projects and Solutions->VC++ Directories->Include files添加boost_1_34_1路徑
在vs2005中編寫如下代碼
#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;
}
在提示下輸入
enter test string
select name from table
得到如下結果,具體為什么自己認真分析
str :select name from table
str :name
str :table