Search code examples
c++std-filesystem

std:: has no member "filesystem" in C++/17


I'm trying to include <filesystem>, but when I use a namespace, it shows this error:

std:: has no member "filesystem"

I know in older times it is <experimental/filesystem> and namespace is std::experimental::filesystem;

but, when i does this, it also give error like that:

    #error The <experimental/filesystem> header providing std::experimental::filesystem is deprecated by Microsoft \
and will be REMOVED. It is superseded by the C++17 <filesystem> header providing std::filesystem. \
You can define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING to acknowledge that you have received this warning.

I'm using Visual Studio 2019, and C/C++ language settings is set to latest version.

So what caused the problem?

Edit 1: all code which cause error:

#include <iostream>
#include <Windows.h>
#include <filesystem>

namespace fs = std::filesystem;

int main() {

    return 0;
}

edit 2: All code, in older, which has error too:

#include <iostream>
#include <Windows.h>
#include <experimental/filesystem>

namespace fs = std::experimental::filesystem;

int main() {


    return 0;

}

edit 3: Visual Studio 2019 project configuration settings -> general properties:

Platform Toolset: Visual Studio 2019 (v142) C++ Language Standart: ISO C++17 Standart (std::c++17) Windows SDK version 10.0 (Lastest installed version)


Solution

  • After Struggling 10 hours, I got the answer. I'll post it for who'll get same problem with me in the future;

    in my case, Visual Studio Configuration settings are only set in x86 configuration, so set configurations to all configurations, than use these steps:

    1- Project properties -> configuration properties -> general -> and set language standart as "C++ Language Standart: ISO C++17 Standart (std::c++17)"

    2- Project properties -> C/C++ -> Language -> and set language standart as "C++ Language Standart: ISO C++17 Standart (std::c++17)"

    3- (Most Important) Project properties -> C/C++ -> Commend Line -> additional options, paste this: /Zc:__cplusplus