How to change the DEFAULT C++ Language with Visual Studio 2022? - c++

I've read about how to change these settings in .props files for VS 2019, but those solutions didn't work for me with VS 2022.
I simply want the DEFAULT C++ Language Standard to be CPP20, not CPP14.
I don't like having to change it for every project as sometimes I forget and thus my code won't run.

https://www.learncpp.com/cpp-tutorial/configuring-your-compiler-choosing-a-language-standard/
Setting a language standard in Visual Studio
As of the time of writing, Visual Studio 2022 defaults to C++14 capabilities, which does not allow for the use of newer features introduced in C++17 and C++20.
To use these newer features, you’ll need to enable a newer language standard. Unfortunately, there is currently no way to do this globally -- you must do so on a project-by-project basis.
Warning
With Visual Studio, you will need to reselect your language standard every time you create a new project.
To select a language standard, open your project, then go to Project menu > (Your application’s Name) Properties, then open Configuration Properties > C/C++ > Language.

Related

Visual Studio 2019 C++ and std::filesystem

Now, I would have not expected That, after 'upgrading' to a 'newer' version of the compiler.
In VS2017 std::filesystem was available through std::experimental::filesystem, Now after upgrading to VS2019 to my surprise it is not available at all. Not in std::experimental nor std::filesystem.
and YES, I've tried setting c++17 from project's settings even the 'latest draft' thing, any ideas?
For the sake of completeness and people searching this in the future.
To switch to C++17' std::filesystem in Visual Studio (regardless VS2019 or VS2017) you need to:
change the language standard in Project properties -> Configuration Properties -> C/C++ -> Language -> C++ Language Standard to at least ISO C++17 Standard (/std:c++17)
(Can also be found in Project properties -> Configuration Properties -> General -> C++ Language Standard)
change #include <experimental/filesystem> to #include <filesystem>
change in the source code all appearance of std::experimental::filesystem to std::filesystem
fix the possible differences between the experimental and final filesystem versions
For all those who struggle with porting their existing Visual Studio 2017 projects into Visual Studio 2019, having proper project settings and pulling their hair out to no avail:
in file VC\Tools\MSVC\14.26.28801\include\filesystem
there's:
#if !_HAS_CXX17
now for why this flag is not automatically being set when changing projects settings I have no idea.
Thus I've used:
#define _HAS_CXX17 1
#include <filesystem>
in my files as a workaround. Works fine.
Update: On another system, within project's file there was
<LanguageStandard>stdcpplatest</LanguageStandard>
<AdditionalOptions>/std:c++14 %(AdditionalOptions)</AdditionalOptions>
The latter line was resulting in problems (obviously). Switching higher-level project settings does not remove such optional settings (obviously).
I hit the same issue [include filesystem] with the 2019 version (Microsoft Visual Studio Community 2019 Version 16.6.0) in spite of C++17 language selection.
I had to explicitly change the platform and the Active Solution platform to x64 in the configuration window (though, I started with x64). With this, the error is gone.
You will have to update your Visual C++ redistributable if you haven't. Then under project properties > Configuration Properties > C++ Language Standard: Select C++17 or higher.
You could try setting it to that by default. See this:How to change default C++ language standard in Visual Studio 2019?
The correct solution to that is:
For Xcode:
go to project properties
under build Settings, scroll down to Apple Clang- Language- c++.
there you have to select c++ language dialect and set it to C++17[-std=c++17].
cheers
Singh

What is the reason behind Visual Studio 2019 defaulting to the C++ 14 standard?

I was trying to use inline variables, but found out VS defaults to C++14 and one must manually change this on a project by project basis. Why doesn't Microsoft automatically update VS to the C++17 standard for all projects?

General usage of c++ in visual studio

Is it possible to write a c++ code in Visual Studio without using c++.net?
I'm learning c++ at the moment - Using a book.
But I like the Visual Studio IDE but I don't know if it supports c++ or just c++.net.
I usually create a new (empty) directory and copy the source file(s) into that directory, then when creating the Visual Studio project using the name of the directory. To create a standard C++ console program, choose "... console application", then click on next, clear the check boxes below "empty project", and check "empty project". Once you're into the project, click on project, and "add existing item" to add the source file name(s).
If you want 64 bit mode, you'll need to right click on the project name, then properties, then configuration manager, then new, and select x64. It doesn't matter if you do this for debug or release build, it will set x64 mode for both build modes.
Yes, you can. Visual studio supports two types of C++ applications:
C++/CLI (also called managed C++) - Under Visual Studio project wizard, these kind of projects are grouped under CLR
Native C++ - Under Visual Studio project wizard, these are the projects grouped under Win32, MFC, ATL
Note, however, that you can always turn a project from native to managed and vice versa by going into the project properties and switching on/off the Common Language Runtime Support (/clr), so make sure this option is turned off (No CLR).
Also, be aware that different C++ compilers not always support the same C++ features (even if they are part of the standard), and some C++ compilers implement their own extensions to the language. In the case of Visual Studio, it defines Microsoft Extensions to C and C++ that can be turned off (Za) to be more ANSI compliant.
Visual Studio is actually notoriously late when it comes to supporting the C++ standard. Even now, some C++11 features are not part of the latest Visual Studio so keep this in mind when wondering why something you read in a book does not work in Visual C++.
One last note. Avoid using ATL and MFC if you try to be cross-platform compatible. Even if you don't want to be cross-platform compatible, ATL and MFC are only supported by Visual C++ and using them will lock you to using Visual Studio. Now with the Community Edition, both ATL/MFC are available for free if you are an independent developer or a small company, while historically, ATL/MFC were paid-version only as they are not part of Visual Studio Express editions.
It depends on which variant of Visual Studio you're using. If Express edition you want "for Desktop" in order to do ordinary standard C++. With full Visual Studio there's no problem.

Visual studio 2010 automatically switched to C++/CLI compiler

I've been working to a C++/CLI project in the last few months.
Now I'm back to C++ but seems that VS 2010 has set to use C++/CLI compiler even for standard C++ projects.
I just created a new C++ empty project but when I compile the code, it seems using C++/CLI compiler.
Intellisense is disabled as well.
How can I restore the default C++ compiler to my project ?
Choose Project -> Properties from the menu bar. In the Project properties window, under Configuration Properties -> General, make sure that Common Language Runtime Support is set to No Common Language Runtime Support.

Native C++ programs in Visual Studio

I'm confused in my understanding of the relationship between Visual Studio and .NET. I want to write a C++ application, but not a ".NET C++" application. By this, I mean that my understanding is that everything built in .NET land gets compiled to a CLI-compatible intermediary code (just like "JVM" languages like Java and Groovy compile to the same bytecode).
But I don't want my app compiled to an intermediary bytecode...I want it compiled down to raw binary!
Does Visual Studio do this? Or is .NET forced down my throat the minute I choose VS as my C++ IDE? If so, whats a "raw C++" alternative to VS?
Thanks in advance!
Visual Studio is an IDE, which is orthogonal to any specific language or compiler.
Visual C++ is a compiler that supports the C, C++, and C++/CLI languages.
In Visual Studio, create a Visual C++ project from one of the 'Win32' (as opposed to 'CLR') project templates and your program won't have any .NET dependency.
there is that /clr compiler switch when compiling a c++ app. Without it, you will get a pure native binary and cannot use any. NET specific features within your code.
By selecting a project template or by setting the corresponding project property, VS will automatically choose if the switch is on or off.
Visual Studio still supports 100% native C++ applications as will as managed applications. When creating a new app just choose the "Win32 Console Application" to create a native application. For existing applications you can change / verify by doing the following
Right Click on the project and select "Properties"
Navigate to Configuration Properties -> C/C++
Make sure that "Common Language Runtime Support" is set to "No Common Language Runtime Support"