VC使用boost库解析正则表达式方法

来源:计算机等级考试    发布时间:2012-08-28    计算机等级考试视频    评论

  boost库安装比较麻烦,需要自己编译源文件,我整理了一下,如果仅仅需要做正则表达式,按下面的代码敲就行了:
  cmd
  vcvars32.bat
  cd D://boost_1_32_0//libs//regex//build
  d:
  nmake -fvc6.mak
  nmake -fvc6.mak install
  注意,别看下载下来的数据包没有多大,解压缩之后达到了100多M,编译完之后为109M,占用131M,所以安装时一定注意空出足够的空间,敲入 nmake -fvc6.mak后等待的时间比较长,屏幕上还会出现一大堆英语,可以不做考虑.按照步骤往下敲就行了.压缩包内文档很详细,参照文档继续就可以了.
  在VC6中集成:Tools->Options->Directories->Include files
  加入:D://boost_1_32_0
  编写一个源程序测试一下:
  #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;
  }
  输入: select name from table
  输出: str:select name from table
    str:name
    str:table

视频学习

我考网版权与免责声明

① 凡本网注明稿件来源为"原创"的所有文字、图片和音视频稿件,版权均属本网所有。任何媒体、网站或个人转载、链接转贴或以其他方式复制发表时必须注明"稿件来源:我考网",违者本网将依法追究责任;

② 本网部分稿件来源于网络,任何单位或个人认为我考网发布的内容可能涉嫌侵犯其合法权益,应该及时向我考网书面反馈,并提供身份证明、权属证明及详细侵权情况证明,我考网在收到上述法律文件后,将会尽快移除被控侵权内容。

最近更新

社区交流

考试问答