msvc2019使用filesystem

#define _USE_STD_FILESYSTEM
#ifdef _USE_STD_FILESYSTEM
#include 

#if _HAS_CXX17

#include 
namespace fs = std::filesystem;
//using namespace std::filesystem;

#else

#define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING
#include 
namespace fs = std::experimental::filesystem;
//using namespace std::experimental::filesystem;

#endif //!_HAS_CXX17

#else

#include 
namespace fs = boost::filesystem;
//using namespace boost::filesystem;

#endif //!_USE_STD_FILESYSTEM

int main()
{
    fs::path p("d:/test/a.log");
    fs::exists(p);
    return 0;
}

1.如果使用msvc默认设置

#include

2.如果 c/c++  ==>  语言 ,更改c++语言标准

#include

msvc2019使用filesystem_第1张图片

完整头文件 CompatibleFileSystem.h

注意

#define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING
#include

#ifndef COMPATIBLEFILESYSTEM_H_123_
#define COMPATIBLEFILESYSTEM_H_123_

#if defined (_MSC_VER) && (_MSC_VER >= 1020)
#pragma once
#endif

#ifndef _USE_BOOST_FILESYSTEM

#include 
#if _HAS_CXX17
#include 
namespace fs = std::filesystem;
//using namespace std::filesystem;
#else

#define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING
#include 
namespace fs = std::experimental::filesystem;
//using namespace std::experimental::filesystem;
#endif //!_HAS_CXX17

#else

#include 
namespace fs = boost::filesystem;
//using namespace boost::filesystem;

#endif //!_USE_STD_FILESYSTEM

#endif // !COMPATIBLEFILESYSTEM_H_123_

你可能感兴趣的:(c++,c++)