Change (use older) c++ version in Visual Studio [duplicate] - c++

This question already has answers here:
Disable c++11 features in Visual Studio2013
(5 answers)
Closed 7 years ago.
Is it possible to use an older version in Visual Studio than c++11? A similar question revealed that it is not possible to use a newer version, but I want the compiler to complain when I am using language features that are only available for c++11.

To completely disable C++11 features in Visual Studio, you must compile with a toolset old enough that it does not have any C++11 features. The last version of Visual Studio to have no C++11 support was VS2008 (question about that here: Visual Studio 2008 with c++11).
To use an older toolset, you must first install that version of Visual Studio, and then modify the "Configuration Properties->General->Platform Toolset" and set it to the appropriate Visual Studio version. When you compile with Visual Studio 2008 toolset, any C++11 usage will be errors.

No, there is no way to disable C++11 features for a Visual Studio project without installing an older MSVC version.

Related

What is the latest C++ standard to target Windows XP with Visual Studio?

Visual Studio 2019 seems to have good support for C++17. Unfortunately, it seems binaries built with it require the Universal CRT to be installed on the target machine, and the minimum supported OS for the UCRT is Vista.
So, if I want to build a binary to target Windows XP, must I use a VS C++ compiler preceding the UCRT? Is that VS 2013, which has some support for C++11?
The latest toolset that has Windows XP support is v141_xp, that is the XP toolset from Visual Studio 2017. It has full C++14 support, and partial C++17 support.
It comes with Visual Studio 2019, too:
Unfortunately, it does not have full C++17 and C++20 support.
The latest update of VS2019 has almost complete C++20 support in v142 toolset, and there is an update expected to make it complete, but it is without XP support.
VS2022 drops Vista and support some C++23 in its v143 toolset. It still ships with v141_xp toolset as optional [deprecated] component.
The v141_xp toolset still has the support of C++14, and partial C++17. It mostly corresponds to the Conformance table where they mention VS 2017. (Say, you will have std::any or terse static_assert, but won't be able to use shared_mutex, as it relies on Vista SRWLOCK)
See also: How to install build tools for v141_xp for VC 2017?

MS Visual Studio 2012 for Windows Desktop - C++11 features

I use MS Visual Studio 2012 for Windows Desktop (C++) and I've recently started using C++11 features,such as range-based for loop,lambda functions,final,override and so on.
But I cannot use some of the features,like std::initializer_list,user-defined signatures...
I don't understand why this version of MS Visual Studio does support some,but not all of them.
Should I start using a newer version,or what?
Thanks.
Yes, you should start using a newer version, because as it happens, newer versions implement new features.
Also, your question doesn't really ask a question.
You can find comparison tables of supported C++11 features in recent versions of Visual Studio on the MSDN website: http://msdn.microsoft.com/en-us/library/hh567368.aspx

Why do the source files that compile on Visual studio 2013, have syntax errors on visual studio 2008?

When i write source files in visual studio 2013 and attempt to use the same source files for visual studio 2008, the files have syntax errors. Is it possible for visual studio 2013 to mimic the way that visual studio 2008 compiles?
The language I'm using is C++.
Visual C++ in VS2013 allows c++ 11 compliant code but VS2008 does not, so any syntax you use which is new to the standard will not compile under VS2008. You can either remove the syntax or look into the c++ futures libraries in VS2008 to see if what you need is there, or maybe in boost.
http://msdn.microsoft.com/en-us/library/bb982198(v=vs.90).aspx
and
http://www.boost.org/
New versions of VS tend to do the following which will break compatibility with older versions.
Support new C++ standards
Increase conformance with existing standards
Deprecate/remove proprietary extensions and incorrect implementations
Generally speaking, ISO standard C++ is backward compatible (there will always be some exceptions), which means most of the older syntax will compile on newer standards. So you will likely have more success if you create the sources first in VS2008 and then "migrate" to VS2013 (rather than create it in VS2013 first which may have incompatible syntax with VS2008).

How to "activate" c++11 standard in visual studio 2010?

I am new to c++ programming and I need to use the Thread class in my VS 2010 project.
I've found this reference, but when I try the following:
#include <thread>
VS 2010 obviously tells me 'Error: cannot open source file "thread"'. I understand that I need to "activate" c++11 standard somehow. I do not even know where to start.
So what should I do to use () c++11 standard in visual studio 2010?
std::thread is obviously not in VS 2010. I think it was added with VS 2012, which is also supported by this question and answer. Is there any specific reason you're using 2010 rather than the latest version, 2013, which supports far more part of C++11?
Also to note: Contrary to GCC, MSVC doesn't have an "opt-in" for newer standards. It just supports them out of the box as far as implemented.
The Visual C++ compiler is not fully C++11 compatible. C++11 features had been supported since Visual Studio 2010 and added incrementally. Not even the next version of Visual Studio will provide full C++11 compatibility. A matrix of C++11 features available in different versions of Visual Studio can be found here:
C++0x Core Language Features In VC10: The Table
C++11 Features in Visual C++ 11
C++11/14 STL Features, Fixes, And Breaking Changes In VS 2013
C++11 is enabled by default, but there is not many features implemented in VS 2010. C++11 standard library is missing many headers in VS 2010. Here is a comparison of a last few VS releases regarding the C++11 support.
Here's what I've found by myself.
To "activate" c++11 in visual studio you need to set "Platform Toolset" in project->properties to v110 or above. So that's how visual studio will understand that it should use c++11 features.
BUT!
The Visual C++ compiler is not fully C++11 compatible. C++11 features had been supported since Visual Studio 2010 and added incrementally. Not even the next version of Visual Studio will provide full C++11 compatibility.
Marius Bancila
So it worked for <thread> (and <future>) in visual studio 2012.
As I suggest it's impossible to set Platform Toolset above v100 in vs2010, so it's impossible to "activate" c++11 in vs2010.
Conclusion:
to use c++11 standart features in visual studio you will need to use 2012 and higher version which supports Platform Toolset v110 and above.
Correct me please if I'm wrong!
d= (◕‿↼ ) C++11 is enabled by default, But unfortunately, not even "Visual Studio 2017" is fully C++11 compliant.
(I got here while building Boost, which's build section only mentions their need for C++11 compliant compiler, and NOT with what MSVC version they tested Boost.)
Microsoft says:
"Support for C11 and C17 standards is available in Visual Studio 2019 version 16.8 and later"
But I didn't test their claim yet.

how to enable c++ support in visual studio 2010?

I want to create a C++ project in Visual studio 2010 but I don't
see any template for a C++ project. All I see is visual c# templates.
Please let me know how to enable c++ support in visual studio 2010.
You likely have Visual Studio installed without the C++ compiler. You have to start the installer and alter the installation so that C++ compiler is installed.
You probably need to reinstall it. During installation there is a choice of languages and features. Probably C++ was not chosen when it was installed on your system.