@azmddy
2018-11-02T03:55:11.000000Z
字数 940
阅读 425
Linux C++ Boost
Boost被称为C++的准标准库,这里简单的记录了如何linux平台上使用Boost.
Boost下载地址:https://www.boost.org/users/download/

选择一个下载,然后解压;
下载了一个库,大家第一反应应该就是如何构建它。
但大多数Boost库只是头文件,它们完全由包含模板和内联函数的头文件组成,并且在链接的时候不需要单独编译的库的二进制文件或特殊处理。
如果使用到了单独编译的Boost库,那么就通过构建和安装Boost库了。
$ cd boost_1_68_0# 使用root权限$ sudo su./bootstrap.sh./b2# 将库文件路径添加到环境变量(root)# 库文件路径:/home/azmddy/Downloads/boost_1_68_0/stage/libvim /etc/ld.so.conf.d/boost.confsudo ldconfig
下面提供两个官方实例:
// 不需要链接库参与编译的#include <boost/lambda/lambda.hpp>#include <iostream>#include <iterator>#include <algorithm>int main(){using namespace boost::lambda;typedef std::istream_iterator<int> in;std::for_each(in(std::cin), in(), std::cout << (_1 * 3) << " " );}
// 需要链接库参与编译的#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;}}