Chinaunix首页 | 论坛 | 博客
  • 博客访问: 583846
  • 博文数量: 69
  • 博客积分: 2204
  • 博客等级: 大尉
  • 技术积分: 808
  • 用 户 组: 普通用户
  • 注册时间: 2009-10-11 22:37
个人简介

..微笑着看着杯中的花茶一片片撑开.. ..透明的花瓣里水破开的声音很轻微..

文章分类

全部博文(69)

文章存档

2018年(1)

2017年(2)

2016年(10)

2015年(8)

2014年(6)

2013年(6)

2012年(4)

2011年(8)

2010年(12)

2009年(12)

分类: C/C++

2011-04-08 21:32:30

ubuntu 下安装Boost库的话,最简单的办法就是用软件包管理器,我的环境是ubuntu 10.10 boost版本是1.42. 最好不要跟自己编译的库混装。很容易出现问题。

头文件位置是在 \usr\include\boost
库文件位置是在 \usr\lib

安装好后构建如下文件和代码测试:

#include <boost/regex.hpp>
#include <iostream>
#include <string>
 
int main()
{
    std::string line;
    boost::regex pat( "^Subject: (Re: |Aw: )*(.*)" );
    while (std::cin)
    {
        std::getline(std::cin, line);
        boost::smatch matches;
        if (boost::regex_match(line, matches, pat))
            std::cout << matches[2] << std::endl;
    }
}


新建文件 mail.txt

To: George Shmidlap From: Rita Marlowe Subject: Will Success Spoil Rock Hunter? --- See subject.


编译这步很关键,如果不链接库会出现错误。

g++ -o hello hello.cpp -lboost_regex


生成hello文件,测试结果如下。

$ ./hello < mail.txt

Will Success Spoil Rock Hunter?


参考资料:%E4%BD%BF%E7%94%A8boost/

阅读(2456) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~