185

I want to use C++17 features.

How can I switch compiling from C++14 to C++17 in Microsoft Visual Studio?

Or is it not available in release versions of VS?

6
  • 4
    Which C++17 features? Which version of Visual Studio? If you're asking about C++17 why did you tag your question c++11 and c++14?
    – ildjarn
    Dec 23, 2016 at 23:35
  • 8
    c++17 wasn't available, and I thought that those who are interested in specific versions of C++ knows better how to switch it. For example I want std::vector.emplace_back() to give back a reference to the newly created element. I know that +1 line, and I get that reference, But I would like to know the answer to my question anyway. VS Community 2015 (14.0.25431.01 Update 3)
    – Tudvari
    Dec 23, 2016 at 23:41
  • You should probably check here: blogs.msdn.microsoft.com/visualstudio
    – Mikel F
    Dec 23, 2016 at 23:41
  • 3
    You can't enable specific language dialects in VS, you get whatever they've implemented. You might have pretty good luck with standard library features voted into C++17 if you're using VS21015, but not so much with language features.
    – Praetorian
    Dec 23, 2016 at 23:51
  • 1
    @preat MSVC 2017 has a "latest" setting, but that is not released yet. Dec 24, 2016 at 1:44

6 Answers 6

259

There's now a drop down (at least since VS 2017.3.5) where you can specifically select C++17. The available options are (under project > Properties > C/C++ > Language > C++ Language Standard)

  • ISO C++14 Standard. msvc command line option: /std:c++14
  • ISO C++17 Standard. msvc command line option: /std:c++17

Visual Studio 2022 (MSVC C++20 and the /std:c++20 Switch - C++ Team Blog):

  • ISO C++20 Standard. msvc command line option: /std:c++20

Any Visual Studio:

  • The latest draft standard. msvc command line option: /std:c++latest
9
  • 3
    The syntax -std:c++14, -std:c++17 and -std:c++latest also works, e.g. when you prefer to manually enter compiler options (tested with VS2017).
    – Roi Danton
    Jul 18, 2018 at 7:39
  • Is that not clear from the answer already, or do you specifically mean - instead of the /std: switches I list? Jul 18, 2018 at 11:59
  • 3
    I see the benefit when coming from gcc or clang. Then the - is less intrusive (however the syntax still differs slightly (: instead of =)).
    – Roi Danton
    Jul 18, 2018 at 12:06
  • 1
    @AndreiKrasutski. There is no ISO C++20 yet but some support in /std:c++latest. The C++20 standard is expected next year. I Edited in a comment in my answer. Dec 26, 2019 at 21:46
  • 3
    What C++ standard is used if there is nothing selected in Visual Studio 2017 > Project Properties > C / C++ > Language > C++ Standard dropdown? I have 14, 17 and latest in the dropdown, but none is selected, so how do I find what c++ standard is used in a project in that case?
    – pixel
    Sep 17, 2020 at 16:51
39

MSBuild (Visual Studio project/solution *.vcproj/*.sln):

Add to Additional options in Project Settings: /std:c++latest to enable latest features - currently C++17 as of VS2017, VS2015 Update 3.

https://blogs.msdn.microsoft.com/vcblog/2016/06/07/standards-version-switches-in-the-compiler/

/permissive- will disable non-standard C++ extensions and will enable standard conformance in VS2017.

https://blogs.msdn.microsoft.com/vcblog/2016/11/16/permissive-switch/

EDIT (Oct 2018): The latest VS2017 features are documented here:

https://learn.microsoft.com/en-gb/cpp/build/reference/std-specify-language-standard-version

VS2017 supports: /std:[c++14|c++17|c++latest] now. These flags can be set via the project's property pages:

To set this compiler option in the Visual Studio development environment

  1. Open the project's Property Pages dialog box. For details, see Working with Project Properties.
  2. Select Configuration Properties, C/C++, Language.
  3. In C++ Language Standard, choose the language standard to support from the dropdown control, then choose OK or Apply to save your changes.

CMake:

Visual Studio 2017 (15.7+) supports CMake projects. CMake makes it possible to enable modern C++ features in various ways. The most basic option is to enable a modern C++ standard by setting a target's property in CMakeLists.txt:

add_library (${PROJECT_NAME})
set_property (TARGET ${PROJECT_NAME}
  PROPERTY
    # Enable C++17 standard compliance
    CXX_STANDARD 17
)

In the case of an interface library:

add_library (${PROJECT_NAME} INTERFACE)
target_compile_features (${PROJECT_NAME}
  INTERFACE
    # Enable C++17 standard compliance
    cxx_std_17
)
1
  • I did the dropdown in my VS2017 but still the compiler keep applying C++98 standard, what the heck
    – Travis Su
    Apr 16, 2020 at 8:48
10

Visual Studio 2015 Update 3 does not support the C++17 feature you are looking for (emplace_back() returning a reference).

Support For C++11/14/17 Features (Modern C++)

C++11/14/17 Features In VS 2015 RTM

VS 2015 Update 2’s STL is C++17-so-far Feature Complete

Visual Studio 2015 Update 3

STL Fixes In VS 2015 Update 3

10

Visual studio 2019 version:

The drop down menu was moved to:

  • Right click on project (not solution)
  • Properties (or Alt + Enter)
  • From the left menu select Configuration Properties
  • General
  • In the middle there is an option called "C++ Language Standard"
  • Next to it is the drop down menu
  • Here you can select Default, ISO C++ 14, 17 or latest
2
  • 3
    Remember to do this for 'All Configurations' and 'All Platforms'. That's from someone who's spent an 2 hour figuring out why it still doesn't work! But thanks for the answer.
    – Persixty
    Nov 7, 2020 at 16:40
  • 1
    In the vs2019 that Unreal setup, there is no Configuration Settings -> General -> C++ Language Standard. Can it be added? There is an nmake -> Additional Options that is set to /std:c++14 ... but changing it to c++17 doesn't seem to work.
    – zBeeble
    Jan 25, 2022 at 20:20
6

If bringing existing Visual Studio 2015 solution into Visual Studio 2017 and you want to build it with c++17 native compiler, you should first Retarget the solution/projects to v141 , THEN the dropdown will appear as described above ( Configuration Properties -> C/C++ -> Language -> Language Standard)

-1

VS Code 2020 version

In tasks.json file, (after you build and debug with the g++-9)

Add -std=c++2a for 2020 features (c++1z for 2017 features). Add -fconcepts to use concept keyword

"args": [
   "-std=c++2a",
   "-fconcepts",
   "-g",
   "${file}",
   "-o",
   "${fileDirname}/${fileBasenameNoExtension}"
],

now compile and you can use the 2020 features.

3
  • There is no Visual Studios 2020, this is for V.S. Code
    – JΛYDΞV
    Aug 31, 2021 at 18:13
  • But the question is not asking "only-for" VS Studio. If you re-read the question, at the end of the line "it's not avaiable in release versions of VS?". The question is flexible, no need to be strict.
    – Ahmet
    Sep 6, 2021 at 12:26
  • This question is not that flexible, and if it were, it would need to be closed. It wouldn't be focused enough. VS Code is not a different version of Visual studio. One is an Integrated Development Environment, and one is an Editor. One pulls up the code that you write, the other is embedded into the file system of the project it is working on. One is funded by Microsoft, one is developed by Microsoft. One is portable to Linux, one is not. A configuration for one, will not work for the other. You might as well answer how to compile C++17 in Notepad.
    – JΛYDΞV
    Sep 6, 2021 at 21:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.