Windows下Boot的编译和使用

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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值