hengheng123456789

  BlogJava :: 首页 :: 联系 :: 聚合  :: 管理
  297 Posts :: 68 Stories :: 144 Comments :: 0 Trackbacks
转自: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

posted on 2011-01-12 10:33 哼哼 阅读(707) 评论(0)  编辑  收藏 所属分类:

只有注册用户登录后才能发表评论。


网站导航: