How to change default C++ language standard in Visual Studio 2019?

11.1k views Asked by At

I'd like to use C++17 for my projects without always having to change it in the properties when starting a new one. Is this possible?

Thanks!

3

There are 3 answers

1
SoronelHaetir On BEST ANSWER

Edit the property sheet under the View -> Other Windows -> Property Manager Next open the tree for a project and then the platform you wish to change.

The settings here are inherited by default for all project configurations of the corresponding platform so right click the node for "Microsoft.Cpp..User" and then go to C/C++ -> Language and set the language standard you want then click Ok.

You may need to right click the project node and select save, I'm not sure if that is actually necessary or not.

5
dxiv On

To change the defaults only for new projects, see How to change the default C++ template file?.

To change the defaults for all C++ projects, look for the following two .props files in $(UserRootDir), usually C:\Users\<user name>\AppData\Local\Microsoft\MSBuild\v4.0.

    Microsoft.Cpp.Win32.user.props
    Microsoft.Cpp.x64.user.props

Then insert the following under Project/ItemDefinitionGroup/ClCompile.

    <ConformanceMode>true</ConformanceMode>
    <LanguageStandard>stdcpp17</LanguageStandard>

If the .props files did not exist and you had to create them from scratch, each one would have the following complete contents.

<?xml version="1.0" encoding="utf-8"?> 
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemDefinitionGroup>
    <ClCompile>
      <ConformanceMode>true</ConformanceMode>
      <LanguageStandard>stdcpp17</LanguageStandard>
    </ClCompile>
  </ItemDefinitionGroup>
</Project>

See my other answer here for more details about the property files, including where to find the per-machine defaults (in $(VCTargets)), instead of the per-user ones (in $(UserRootDir)).

0
g_cardillo On

You can do that by setting (left down corner) -> command palette.. -> c/c++ Edit configuration(UI). It will bring you to the IntelliSense Configurations. From there you can change the version for both C and C++.