4

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!

dxiv
  • 16,984
  • 2
  • 27
  • 49
Rintala
  • 51
  • 1
  • 6

3 Answers3

4

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)).

dxiv
  • 16,984
  • 2
  • 27
  • 49
  • 1
    While this answer seems very thorough (as does the one behind the link 'How to change the default C++ template file?') it is a bit overwhelming too. I'll probably check it out later if I'll stay using VS but for now @SoronelHaetir 's answer is rather simple and works. – Rintala Sep 28 '20 at 04:39
  • @Rintala That's your call, of course, and in the end it's a matter of preference. Just keep in mind that editing the `.props` file (whether via the GUI or directly) changes the default setting for *all* projects, past and future, that do not explicitly define their own `/std` conformance level. – dxiv Sep 28 '20 at 05:31
  • Good thing you pointed that out. At the moment it is of no importance whether the past project properties also change but now I understand a bit more what I just did :) I'm just learning programming as a hobby and all these bloated IDE's are exhausting. In fact I just found onlinegdb.com and for my purposes it is faster and uses the same keyboard shortcuts as VS Code (something I've struggled with the VS IDE) Anyways, I'm sure other people will find your answer helpful! – Rintala Sep 28 '20 at 13:18
  • I found the props file in `C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160` – cho_uc Mar 23 '21 at 14:39
  • @cho_uc That's the `$(VCTargetsPath)` which you would use to change the per-machine defaults instead of the per-user ones. – dxiv Mar 23 '21 at 15:02
2

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.

SoronelHaetir
  • 14,104
  • 1
  • 12
  • 23
  • I did right click the project name and chose to save but when creating a new project (and thus closing the previous) VS opened a popup saying "One or more inherited property sheets have not been saved. Save now" so I think this was the crucial step. Working now beatifully! Thanks! – Rintala Sep 28 '20 at 04:35
0

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++.

ouflak
  • 2,458
  • 10
  • 44
  • 49