2

I'm running VS2019 v16.6.2

I have been following the solution to this question on how to set VS2019 to C++17 and define "ISO C++17 Standard (/std:c++17)" as the source language. However, the compiler is not using C++17 standard. I wrote the following test program to see the compilers settings. Output follows.

#include <iostream>
#include <filesystem> // C++17 standard header file name

int main() {

#if !_HAS_CXX17
    printf("No C17");
#endif

    printf("\n%i", _MSVC_LANG);
    printf("\n%i", _HAS_CXX17);

    printf("\n\nPress any key to exit.");
    getchar();
    return 0;
}

Output:

No C++17
201402
0

Press any key to exit.

What am I missing to set the language standard? I need to use c17 because I want to use the filesystem library.

Ben
  • 427
  • 5
  • 17
  • Does this answer your question? [Is '\_HAS\_CXX17' marco usable in custom project headers to enable C++17 language set features?](https://stackoverflow.com/questions/52379233/is-has-cxx17-marco-usable-in-custom-project-headers-to-enable-c17-language) – Adrian Mole Oct 16 '20 at 10:30
  • I don't think so, but it did point me to the __cplusplus value. In my case here it's 199711. Another pointer to my version of VS not listening to its settings. – Ben Oct 16 '20 at 10:48
  • 1
    Did you try adding the `/Zc:__cplusplus` switch to your settings? – Adrian Mole Oct 16 '20 at 10:49
  • Yes. I added /Zc:__cplusplus as an additional switch to the cli arguments in the project properties. – Ben Oct 16 '20 at 10:56
  • 2
    Works just fine as posted. Use Project > Properties and pay attention to the two comboboxes at the top of the dialog. You need to make sure that "All Configurations" and "All Platforms" are selected. – Hans Passant Oct 17 '20 at 17:07
  • C++17’s is supported. This is a completely new implementation, incompatible with the previous std::experimental version, necessitated by symlink support, bug fixes, and changes in standard-required behavior. Currently, including provides the new std::filesystem and the previous std::experimental::filesystem, and including provides only the old experimental implementation. The experimental implementation will be REMOVED in the next ABI-breaking release of the libraries. – Barrnet Chou Oct 19 '20 at 03:16
  • I set the properties and tested this code. It worked fine. So, I think it may be because the property platform setting and the running platform setting are inconsistent. You could check whether `Debug/Release` in `Properties` is the same as `Debug/Release` in `Solutions Configurations`. – Barrnet Chou Oct 19 '20 at 03:21
  • @Hans Passant. Thanks, I forgot to check the Configuration titles. :/ That fixed it. – Ben Oct 19 '20 at 07:55

1 Answers1

0

When editing the project properties, make sure:

  • Configuration is set to All Configurations, and
  • Platform is set to All Platforms.

Otherwise your changes may not be applied to your currently active build configuration and platform.

(I had the OP's exact problem but it took me 2 visits to this question before I realized the solution was buried in the comments.)

Isaac Sutherland
  • 3,082
  • 4
  • 28
  • 37