12

Is there a way to disable C++11 features when writing code in Visual Studio 2013?

I want my code to also compile on older compilers like VS 2008.

I tried to change via: project->properties->general->platform tool-set, and change "Visual Studio 2013 (v120)" to something older, but this is the only thing I have in the drop down menu there.

midor
  • 5,487
  • 2
  • 23
  • 52
user3066442
  • 265
  • 3
  • 9

5 Answers5

10

You can't.

Unfortunately you can not disable C++11 features and downgrade to C++03 or C++98 in Visual Studio. You can see what features belongs to C++11 here and here, try not to use them.

However a better choice is to use older VS versions to make sure that you don't use any new feature.

Personally, I use MinGW/GCC in Windows and I can disable C++11 by using a compiler switch -std=c++03, -std=c++98 or not using -std=c++11.

masoud
  • 55,379
  • 16
  • 141
  • 208
8

If you have other versions of Visual Studio installed then you can select the older tool set. This may help a little.

A better solution, IMHO, is to set up a continuous integration server that builds your code for all supported compilers, configurations and platforms. You will then get build breaks as soon as you do something that isn't supported. Ideally the CI server also runs all of your unit tests so that you also see if any of your configurations break your tests.

Len Holgate
  • 21,282
  • 4
  • 45
  • 92
2

Visual Studio 2015 Update 3 introduces two new switches (/std:c++14 and /std:c++latest) to give you control over the version of the C++ programming language you want to use in your projects. In this update, if you specify a language version that isn’t any of those, the compiler will ignore the switch (with a warning) and default to C++14.

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

Claus Klein
  • 149
  • 1
  • 3
0

Either use a compiler which allows to set the used standard explicitly (Clang and GCC allow to choose the standard version) or make yourself familiar with the changes in C++11 so you can avoid them in your code.

If you need a reference: http://en.cppreference.com/w/ The sides show clearly in which standard version a certain feature was introduced.

Jan Henke
  • 875
  • 1
  • 15
  • 28
  • 13
    It is pretty easy to mistakenly use C++11 features when trying to write C++03 code. For example, a std::vector in C++03 requires that elements be [Copy-Assignable](http://en.cppreference.com/w/cpp/concept/CopyAssignable) and [Copy-Constructable](http://en.cppreference.com/w/cpp/concept/CopyConstructible), while C++11 removes those restrictions. So in some cases saying "avoid C++11 features" is as useless as a statement as "avoid writing bugs". – JDiMatteo Jan 08 '15 at 20:20
0

Configure Visual Studio to use a different compiler that does not support C++11 features. Intellisense will still show C++11 features, but you can catch issues on a local compile before checking it in.

How to use GCC with Microsoft Visual Studio?

Community
  • 1
  • 1
Denise Skidmore
  • 2,286
  • 22
  • 51