下载boost
官网:
https://www.boost.org/
1.71.0下载地址:
https://dl.bintray.com/boostorg/release/1.71.0/source/
解压下载的文件
tar -zxvf boost_1_71_0.tar.gz
进入解压的文件路径
cd boost_1_71_0
执行命令
sudo ./bootstrap.sh
在执行下面的命令,这样头文件就被默认安装在/usr/local/include头文件下,库文件就被默认安装在/usr/local/lib下
sudo ./b2 install
配置环境变量
vim /etc/ld.so.conf
添加/usr/local/lib
执行ldconfig
测试代码
#include <iostream>
#include <boost/regex.hpp>
#include <boost/algorithm/string.hpp>
using namespace std;
int main(){
string str = "data-num=\"1056\"";
boost::regex reg("\\d{1,6}");//{1,6}表示\d重复1-6次,\d表示匹配整数
boost::smatch what;
string::const_iterator begin = str.begin();
string::const_iterator end = str.end();
boost::regex_search(begin,end,what,reg);
string result(what[0].first,what[0].second);
cout << result << endl;
return 0;
}
编译
g++ -o test test.cc -std=c++11 -I /usr/local/include -L /usr/local/lib -lboost_regex