boost是C++开发的一个第三方类库,并且是很重要的一个类库,下面简单讲述一下其安装和使用过程。
1 下载、安装
下载&&解压Boost libary
打开“Developer Command Prompt for VS2015” (PS:这个程序在哪个位置我也不知道,通过开始进行搜索,就ok了),定位到刚才解压的boost library目录下
$boostrap.bat
$b2.exe(ps:这个程序执行时间很长),执行完成后,会显示一下部分,这也就是我们下一步调用的关键
2 使用
新建 Win32 Console Application,其他使用默认参数
写一个测试函数,测试VS是否正常
// ConsoleApplication1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<iostream>
#include<stdlib.h>
int main()
{
std::cout << "Hello,World!" << std::endl;
system("pause");
return 0;
}
将boost的相关文件夹添加到编译和链接路径:
Properties->C/C++ ->Additional Include libaries 将 E:\boost_1_63_0 加入编译路径;
Properties->Linker ->Additional Libraries Directories 将 E:\boost_1_63_0\stage\lib加入链接路径;
编写下面代码进行测试:
// ConsoleApplication1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<iostream>
#include<stdlib.h>
#include<boost\regex.hpp>
int main()
{
std::string line = "Subject:Re:You have installed boost successfully.";
boost::regex pat("^Subject:(Re:|Aw: )*(.*)"); \
boost::smatch matches;
if (boost::regex_match(line, matches, pat)) {
std::cout << matches[2] << std::endl;
}
system("pause");
return 0;
}
ok!