I am using Visual Studio Community 2017 15.8.2. I am trying to use the solution from this SO thread to create a directory for every element of the path if it doesn't exist.
However, on line which calls create_directories
I get an error: namespace "std::experimental::filesystem" has no member "create_directories."
I tried with both std::experimental::filesystem
and std::filesystem
with no success.
I tried changing c++ version in project properties to c++17 by setting the language standard to ISO C++17 Standard (/std:c++17)
, still same error.
When I step into filesystem namespace to see the header I see that there is no create_directories function.
According to this there should be such a function, but in the header file I'm reading I only see the path
class out of all those classes and functions. The location of the header file is:
C:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.15.26726include
Here is how my code looks like:
#include "pch.h"
#include <fstream>
int main(){
namespace fs = std::experimental::filesystem; // In C++17 use std::filesystem.
try {
fs::create_directories("C:\Program Files\Test");
}
catch (std::exception& e) { // Not using fs::filesystem_error since std::bad_alloc can throw too.
std::cout << e.what() << std::endl;
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…