在Windows和Visual Studio上安装Boost
下载并安装boost
1,在boost的网站上下载一个boost的Windows版本的安装器。
http://www.boost-consulting.com/download/windows
这个程序会自动下载和安装boost。
整个Boost有接近1G那么大。
2,或者你也可以直接在boost网站上下载完整版的boost,下载以后安装。
建议你使用第一种方式下载。因为那个程序的下载速度非常快。我选择的是从日本下载。
-
-
现在,可以编写我们的第一个boost程序了。
#include "stdafx.h"
#include <iostream>
#include <cassert>
#include <string>
#include "boost/regex.hpp"
int main() {
// 3 digits, a word, any character, 2 digits or "N/A",
// a space, then the first word again
boost::regex reg("d([a-zA-Z]+).(d|N/A)s");
std::string correct="123Hello N/A Hello";
std::string incorrect="123Hello 12 hello";
assert(boost::regex_match(correct,reg)==true);
assert(boost::regex_match(incorrect,reg)==false);
}
在“附加库目录”中包括boost的lib库目录文件夹。
对于我的配置来说,这里需要输入D:C++Runtimoostoost_1_34_1lib
-
在Visual Studio中启用boost
需要在项目属性中附加boost的目录。
我选择的安装Boost的目录如下:
D:C++Runtimoostoost_1_34_1
1,在“附加包含目录”中添加对boost头文件目录的包含。以便正确include boost的头文件。
对于我的配置来说,这里需要输入D:C++Runtimoostoost_1_34_1。
这个目录下面包含了头文件:bind.hpp
2,还需要附加boost的lib和dll文件
-
转自:http://www.stor-age.com/techupdate/2008/0301/748247.shtml
===============================================
按照上述安装完成者之后,编译给出的例子,编译 出错:
无法打开文件“libboost_regex-vc90-mt-gd-1_44.lib”
网上找了解决方案,使用release版本编译无错,或是按照原来的boost源码,自行编译生成lib文件,再加入即可;
如仅仅是为了测试boost是否安装成功,可使用别的列子:
12345678910111213141516171819202122232425262728293031323334#include <iostream>
#include <iomanip>
#include "boost/format.hpp"
int
main(){
using
namespace
std;
using
boost::format;
using
boost::io::group;
// ------------------------------------------------------------------------
// Simple style of reordering :
cout << format(
"%1% d adsdf%2% %3% %2% %1% \n"
) %
"o"
%
"oo"
%
"O"
;
// prints "o oo O oo o \n"
// ------------------------------------------------------------------------
// Centered alignment : flag '='
cout << format(
"_%|=6|_"
) % 1 << endl;
// prints "_ 1 _" : 3 spaces are padded before, and 2 after.
vector<string> names(1,
"Marc-Fran is Michel"
),
surname(1,
"Durand"
),
tel(1,
"+33 (0) 123 456 789"
);
names.push_back(
"Jean"
);
surname.push_back(
"de Lattre de Tassigny"
);
tel.push_back(
"+33 (0) 987 654 321"
);
for
(unsigned
int
i=0; i<names.size(); ++i)
cout << format(
"%1%, %2%, %|40t|%3%\n"
) % names[i] % surname[i] % tel[i];
cerr <<
"\n\nEverything went OK, exiting. \n"
;
getchar
();
return
0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· .NET周刊【3月第1期 2025-03-02】
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· [AI/GPT/综述] AI Agent的设计模式综述