您的位置:首页 > 其它

Windows下Boot的编译和使用

2016-10-08 14:56 309 查看
1。首先在Boost的官网下载Boot源码,分为Windows版本和Linux版本。下载好以后进行加压(我的解压目录是:E:\C++\Library\boost_1_62_0)。

2。Windows下Boot的编译需要根据自己的Visual Studio版本,然后选择编译(x86,x64)版本,以及(Debug,Release)版本。我自己的是VS2013。从开始菜单打开VS的Tools Command Prompt进行编译。我编译的是VS2013的x86版本。所以打开VS2013 x86 Native Tools Command Prompt。

3。 使用cd命令切换目录到到解压好的Boot。运行bootstrap.bat命令,会生成一个b2.exe。

4。 运行./b2 —toolset=msvc-12.0进行编译。(运行./b2 –help可以查看编译相关的选项)。因为我的是VS2013对应的就是msvc-12.0。根据自己的实际情况调整。

编译好了以后,打开VS使用Boost进行开发。

首先设置Include文件目录:依次点开Properties->C/C++->Additional Include Directories添加E:\C++\Library\boost_1_62_0

然后设置lib文件目录:依次点开Properties->Linker->Additional Library Directories添加E:\C++\Library\boost_1_62_0\stage\lib

下面是一个filesystem的入门程序:

#include <iostream>
#include <string>
#include "boost\filesystem.hpp"

using namespace boost;
using std::cout;
using std::string;

int main()
{
string fileName("C:\\Users\\theone\\Desktop\\readme.txt");
auto filePath = filesystem::path(fileName);

if (filesystem::exists(filePath))    // 判断该path是否存在
{
if (filesystem::is_regular_file(filePath))        // 判断该path是不是一个普通文件
cout << filePath << " size is " << filesystem::file_size(filePath) << '\n';

else if (filesystem::is_directory(filePath))      // 判断该path是不是一个目录
cout << filePath << " is a directory\n";

else
cout << filePath << " exists, but is not a regular file or directory\n";
}
else
cout << filePath << " does not exist\n";

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: