安装
Boost下载(http://www.boost.org/):boost_1_68_0.zip
解压到D:\Program Files
为vs2017添加环境变量PATH: D:\Program Files\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.10.25017\bin\HostX64\x64
在 x64 Native Tools Command Prompt for VS 2017(或者 Developer Command Prompt for VS 2017)中进入boost目录:cd d:\program files\boost_1_68_0
输入bootstrap.bat (或bootstrap.bat vc141 显式地指定VC版本版本号为:VS2017-->vc141)
bootstrap.png
在d:\program files\boost_1_68_0目录中生成了b2.exe和bjam.exe
在目录d:\program files\boost_1_68_0下有一个项目配置文件project-config.jam,用记事本或其他文本编辑工具打开,做如下修改:
project-congif.png
run: .\b2 完成编绎。(耗时长)
stage\lib.png
过一段时间后在文件夹d:\program files\boost_1_68_0\bin\vc14\lib下生成.dll及.lib文件。d:\program files\boost_1_68_0\bin.v2是编译产生的临时目录,可删除。
VS2017配置boost
新建项目
new_project.png
编写代码
#include "pch.h"
#include
#include
using namespace std;
int main()
{
using boost::lexical_cast;
int a = lexical_cast("123");
double b = lexical_cast("123.0123456789");
string s0 = lexical_cast(a);
string s1 = lexical_cast(b);
cout << "number: " << a << " " << b << endl;
cout << "string: " << s0 << " " << s1 << endl;
int c = 0;
try {
c = lexical_cast("abcd");
}
catch (boost::bad_lexical_cast& e) {
cout << e.what() << endl;
}
}
修改调试平台
因为编译的静态库和动态链接是64位,选择64位平台
debug.png
设置编译环境及链接
Debug-->boosttest properties...
C/C++ -->General-->Additional Include Directories附加包含目录:
D:\Program Files\boost_1_68_0;
Linker-->General-->Additional Library Directories附加库目录:
D:\Program Files\boost_1_68_0\stage\lib;
调试运行
Fn + CTRL+F5 直接运行