您的位置:首页 > 其它

visual studio 2005 下安装使用boost库 (正则表达式)

2011-05-08 21:42 387 查看
下载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



转载请标明出处:http://jinyun2012.blog.sohu.com/155691639.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: