4

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)

  • 1
    This might be an issue of Windows, instead of C++. Your Windows has installed the c++ library by default but the version of the c++ may be not the c++17. That's it. – Yves Sep 24 '20 at 08:47
  • I use the filesystem library all the time and I have the same compiler as you. You should quote some actual code that generates the error. – john Sep 24 '20 at 08:49
  • 2
    You need to enable C++17 as Language standard: [Visual Studio 2019 C++ and std::filesystem](https://stackoverflow.com/questions/62256738/visual-studio-2019-c-and-stdfilesystem) – user1810087 Sep 24 '20 at 08:49
  • In language settings i can see/set C++17 version, but still have same problem – Ahmet Yusuf Yatkın Sep 24 '20 at 08:51
  • Please add your visual studio configuration to the question. What are the setting in *Configuration Properties -> General*? – user1810087 Sep 24 '20 at 08:57
  • 1
    Please post a [mcve]. It's a mysterious error that should only occur if you try to use `std::filesystem` as a type or variable rather than a namespace. – molbdnilo Sep 24 '20 at 09:13
  • @user1810087, Added Configuration Properties, Added code. – Ahmet Yusuf Yatkın Sep 24 '20 at 09:28
  • Add a predefined macro test: `#if (__cplusplus < 201703L)` / `#error "not C++17 mode"` / `#endif` to test that you've set the dialect options correctly. – Brett Hale Sep 24 '20 at 09:35
  • @BrettHale gives error. what should i do? (as from the question, i set Configuration settings to c++17, also c/c++ tab language standart) – Ahmet Yusuf Yatkın Sep 24 '20 at 09:43
  • @BrettHale I tested that predefined macro test with this code: `if (__cplusplus == 201703L) std::cout << "C++17\n"; else if (__cplusplus == 201402L) std::cout << "C++14\n"; else if (__cplusplus == 201103L) std::cout << "C++11\n"; else if (__cplusplus == 199711L) std::cout << "C++98\n"; else std::cout << "pre-standard C++\n";` and shows C++98 but, I can Compile/use C++11 Codes. I can't get whats going on – Ahmet Yusuf Yatkın Sep 24 '20 at 09:58
  • When you enable C++17 features in Project settings, make sure Configuration and CPU are selected as Active/Active. – rustyx Sep 24 '20 at 10:28
  • Does this answer your question? [How to enable C++17 compiling in Visual Studio?](https://stackoverflow.com/questions/41308933/how-to-enable-c17-compiling-in-visual-studio) – Hans Olsson Jun 10 '21 at 15:31

1 Answers1

12

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