用java的时候觉得挺折腾,回头来弄c++才知道什么叫折腾。。。汗。。。

首先参考我写的这篇文章:http://www.cnblogs.com/qrlozte/p/4100892.html

我从sourceforge把整个boost的zip下载下来以后,我主要是在编译 boost regex的时候出问题了:boost有很多library,regex只是其中一个,怎么编译regex?

当然,第一步是查看文档,找到boost-path/doc/html/index.html打开,翻了半天倒找regex的说明文档(其实可以直接从boost-path/libs/regex/index.html直接找到)

文档里面说:

Building from Source

The Regex library is "just a bunch of source files": nothing special is required to build them.

You can either build the files under boost-path/libs/regex/src/*.cpp as a library, or add them directly to your project. This is particularly useful if you need to use specific compiler options not supported by the default Boost build.

于是找到这个目录,确实发现了不少的cpp文件,直接打开terminal

g++ -c *.cpp

于是报了一大堆找不到头文件的error,一看,是类似于<boost/regex/xxx.hpp>之类的找不到,回过头去看文档,于是,在“Getting Started on Windows”这个页面找到了说明,发现boost-path/boost中全是头文件,该页面说明如下:

This is a sketch of the resulting directory structure:

boost_1_57_0\ .................The “boost root directory”
index.htm .........A copy of www.boost.org starts here
boost\ .........................All Boost Header files
lib\ .....................precompiled library binaries
libs\ ............Tests, .cpps, docs, etc., by library
index.html ........Library documentation starts here
algorithm\
any\
array\
…more libraries…
status\ .........................Boost-wide test suite
tools\ ...........Utilities, e.g. Boost.Build, quickbook, bcp
more\ ..........................Policy documents, etc.
doc\ ...............A subset of all Boost library docs

然后就把boost-path/boost这个文件夹拷贝到MinGW/include目录下,也就是说,得到:MinGW/include/boost,从而成为了编译器默认搜索路径的一部分

再次打开terminal:

g++ -c *.cpp // 编译成.o文件
ar -r boost_regex.a *.o // 打包成.a文件(库文件,类似java的jar包,但是要配合该库的头文件才能使用)

好,参照这篇文章的步骤:http://www.cnblogs.com/qrlozte/p/4100892.html

大功告成

用一个例子结尾:读入一个文件,进行计算(in.txt中第二行的数除以第一行的数,并放入out.txt)

 #include <fstream>
#include <cstdlib>
#include <iostream>
#include <boost/regex.hpp> using namespace std; int main()
{
ifstream ifs("d:/in.txt");
ofstream ofs("d:/out.txt");
if (ifs && ofs)
{
int val = , tmp = ;
string s, data;
getline(ifs, s);
getline(ifs, data);
// convert to integer
val = atoi(s.c_str()); boost::regex expression("[0-9]+");
boost::smatch what; for ( boost::sregex_iterator iter(data.begin(), data.end(), expression), end; iter != end; ++iter )
{
/*
http://www.boost.org/doc/libs/1_57_0/libs/regex/doc/html/boost_regex/ref/match_results.html#boost_regex.match_results.subscript I quote:
Effects: Returns a reference to the sub_match object representing the character sequence that matched marked sub-expression n. If n == 0 then returns a reference to a sub_match object representing the character sequence that matched the whole regular expression.
*/
if ((*iter)[].matched)
{
tmp = atoi((*iter)[].str().c_str());
ofs << (double)tmp / (double)val << " ";
}
}
ifs.close();
ofs.close();
}
else
{
if (!ifs)
cout << "cannot open in.txt" << endl;
else
cout << "cannot create out.txt" << endl;
} return ;
}

in.txt

 36
12,35,64

out.txt

 0.333333 0.972222 1.77778 

c++ 使用boost regex库 总结的更多相关文章

  1. Windows下用Mingw编译Boost.Regex库

    下载Boost库,解压. 定位到regex库文件夹下. GCC所对应的MAKEFILE为gcc.mak 进入命令提示符下,输入make -f gcc.mak 这是如果直接按回车执行的话,会出现错误: ...

  2. vs 2005 使用 boost regex

    第一步: Boost 入门及其VS2005下编译boost库  boost.regex库安装指南  深入浅出之正则表达式(一)  C++中三种正则表达式比较(C regex,C ++regex,boo ...

  3. #include <boost/regex.hpp>

    boost C++的正则表达式库boost.regex可以应用正则表达式于C++.正则表达式大大减轻了搜索特定模式字符串的负担,在很多语言中都是强大的功能. boost.regex库中两个最重要的类是 ...

  4. Boost正则表达式库regex常用search和match示例 - 编程语言 - 开发者第2241727个问答

    Boost正则表达式库regex常用search和match示例 - 编程语言 - 开发者第2241727个问答 Boost正则表达式库regex常用search和match示例 发表回复   Boo ...

  5. Windows下如何使用BOOST C++库 .

    Windows下如何使用BOOST C++库 我采用的是VC8.0和boost_1_35_0.自己重新编译boost当然可以,但是我使用了 http://www.boostpro.com/produc ...

  6. 在C++ Builder6上使用Boost正则表达式库

    本文关键词:正则表达式 c++ python 软件 正则表达式是一种模式匹配形式,它通常用在处理的文本程序中.比如我们经常使用的grep工具,还是perl语言都使用了正则表达式. 正则表达式是一种模式 ...

  7. profile对比std::regex与boost::regex的性能

    c++11标准库的regex比boost库的regex之间的性能差距接近5倍,这是为什么?stackflow上也找到一篇post<c++11 regex slower than python&g ...

  8. C++中三种正则表达式比较(C regex,C ++regex,boost regex)

    工作需要用到C++中的正则表达式,以下三种正则可供参考 1,C regex #include <regex.h> #include <iostream> #include &l ...

  9. 如何在WINDOWS下编译BOOST C++库 .

    如何在WINDOWS下编译BOOST C++库 cheungmine 2008-6-25   写出来,怕自己以后忘记了,也为初学者参考.使用VC8.0和boost1.35.0.   1)下载boost ...

随机推荐

  1. python3-开发进阶Django-debug-toolbar的配置和Django logging的配置

    阅读目录 django-debug-toolbar的配置 Django logging的配置 一.django-debug-toolbar的配置 1.介绍 django-debug-toolbar 是 ...

  2. Java高级架构师(一)第04节:Git基本原理和安装配置使用

    关于Git的常规操作---没有什么特别难点,只做截图记录.

  3. 可见性-volatile

    出处: http://blog.csdn.net/vking_wang/article/details/9982709

  4. iOS页面跳转及数据传递

    转: http://blog.csdn.net/wang9834664/article/details/8025571 iOS页面跳转: 第一种 [self.navigationController  ...

  5. js基础的思维导图

    纯粹转载下,我可画不出这么好看的思维导图,这得感谢@ChokCoco javascript变量 javascript运算符 javascript数组 javascript流程语句 javascript ...

  6. scrapy-splash抓取动态数据例子十

    一.介绍 本例子用scrapy-splash抓取活动行网站给定关键字抓取活动信息. 给定关键字:数字:融合:电视 抓取信息内如下: 1.资讯标题 2.资讯链接 3.资讯时间 4.资讯来源 二.网站信息 ...

  7. 爬虫扒下 bilibili 视频信息

    B站算是对爬虫非常非常友好的网站啦! 修改转载已取得腾讯云授权 在以上两篇文章中我们已经在腾讯云服务器上搭建好了 Python 爬虫环境了,下一步就是在云服务器上爬上我们的爬虫,抓取我们想要的数据: ...

  8. Python 自用代码(递归清洗采标情况)

    将‘ISO 3408-1-2006,MOD  ISO 3408-2-1991,MOD  ISO 3408-3-2006,MOD’类似格式字符串存为: [{'code': 'ISO 3408-1-200 ...

  9. Android——DEBUG 堆栈

    当android系统执行出现死机等致命错误的时候.通常会有堆栈的DEBUG信息打印,一般直接看根本看不出问题是出在哪里!记录下我android4.2 的DEBUG 堆栈log的方法. 撰写不易,转载请 ...

  10. [Spring boot] Integrating with h2 database

    In pom.xml add dependency: <dependencies> <dependency> <groupId>org.springframewor ...