背景:
在 Win 上通过 Visual Studio 运行 c++ 代码,引入头文件 #include <boost/...>,显式无法打开,需要手动下载boost并进行配置。
1、下载boost
Boost官网:Boost Downloads 下载boost,解压,如下所示:

2、运行 bootstrap.bat
通过VS的命令行工具,cd到上面的Boost,运行里面的bootstrap.bat,运行正常后可以出现b2.exe。如果这一步有问题,没有找到cl:
需要手动去vs里面找到cl.exe,添加到环境变量,重新运行。
这一步成果后,会出现b2.exe,如下所示:

通过VS命令行界面运行b2.exe,这一步时间较长。
3、在VS里面添加路径
在VS里面新建一个项目,然后:
项目 -> 属性 -> 配置属性 -> VC++目录,里面有两个地方需要添加:
1、包含目录。写到boost即可。
2、库目录。写到boost\stage\lib。

保存即可。
4、测试
cpp
#include <iostream>
#include <string>
#include <boost/algorithm/string.hpp>
int main() {
std::string input = "Hello, Boost!";
std::cout << "Original string: " << input << std::endl;
// 使用Boost将string转化为大写
boost::algorithm::to_upper(input);
std::cout << "Upper case string: " << input << std::endl;
// 使用Boost将string转化为小写
boost::algorithm::to_lower(input);
std::cout << "Lower case string: " << input << std::endl;
return 0;
}
成功:
