1. 下载boost binary

https://sourceforge.net/projects/boost/files/boost-binaries/1.67.0_b1/

由于我用的是Windows10下的VS2013,所以下载的是这个:

 VS2013第一个应用boost的程序

 

下载后安装,会要求指定一个目录解压,用默认的local目录即可。

安装完成后,目录结构如下:

 VS2013第一个应用boost的程序

 

  1. 用VS2013创建一个c++的console application.

 VS2013第一个应用boost的程序

 

 VS2013第一个应用boost的程序

 

 

 

  1. 创建完成后,加入额外的include路径。

 VS2013第一个应用boost的程序

 

 

  1. 加入额外的lib路径。

 VS2013第一个应用boost的程序

 

 

  1. 在主文件中写入如下的代码:

#include "stdafx.h"

#include <iostream>

#include <boost/filesystem.hpp>

// define a short alias for the namespace

namespace boostfs = boost::filesystem;

 

int _tmain(int argc, _TCHAR* argv[])

{

   if (argc <= 1) {

          std::cerr << "Usage: " << argv[0] << " <filename>"

                 << std::endl;

          return 1;

   }

 

   boostfs::path p(argv[1]);

  

   if (boostfs::exists(p)) {

          std::cout << "File " << p << " exists." << std::endl;

   }

   else {

          std::cout << "File " << p << " does not exist." << '\n';

                

   }

 

 

   return 0;

}

 

 

  1. 编译后,运行程序。

如果参数的路径存在,就会输出File exists, 否则,会输出File does not exist.

相关文章:

  • 2021-12-11
  • 2022-12-23
  • 2022-12-23
  • 2021-11-23
  • 2021-10-31
  • 2021-08-19
  • 2021-11-06
猜你喜欢
  • 2021-06-29
  • 2021-05-05
  • 2021-07-23
  • 2021-11-04
  • 2021-04-29
  • 2021-07-13
  • 2021-09-21
相关资源
相似解决方案