0.12 — Configuring your compiler: Choosing a language standard

With many different versions of C++ available (C++98, C++03, C++11, C++14, C++17, etc…) how does your compiler know which one to use? Generally, a compiler will pick a standard to default to (often not the most recent language standard). If you wish to use a different standard, you’ll have to configure your IDE/compiler to do so. These settings are applied to the active project only. You need to set them again when you create a new project.

Learncpp uses C++17. If your compiler isn’t capable of C++17, you won’t be able to follow all lessons, though the majority is unaffected. Make sure you’re using an up-to-date compiler so you can compile all the examples yourself. There’s an example at the end of this lesson which you can use to test if you set up your compiler correctly.

Code names for in-progress language standards

Note that the language standards are named after the years in which they are finalized (e.g. C++17 was finalized in 2017).

However, when a new language standard is being agreed upon, it’s not clear in what year the finalization will take place. Consequently, in-progress language standards are given code names, which are then replaced by the actual names upon finalization of the standard. For example, C++11 was called c++1x while it was being worked on. You may still see the code names used in places (especially for upcoming version of the language standard, which won’t have a final name yet).

Here’s a mapping of code names to the final names:

  • c++1x = C++11
  • c++1y = C++14
  • c++1z = C++17
  • c++2a = C++20

For example, if you see c++1z, this is synonymous with the C++17 language standard.

Setting a language standard in Visual Studio

As of the time of writing, Visual Studio 2019 defaults to C++14 capabilities, which does not allow for the use of newer features introduced in C++17 (and C++20), some of which are covered in future lessons.

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.

To do so, open your project, then go to Project menu > (Your application’s Name) Properties, then open Configuration Properties > C/C++ > Language.

From there, you can set the C++ Language Standard to the version of C++ you wish to use.

As of the time of writing, we recommend selecting “ISO C++17 Standard (/std:c++17)”, which is the latest stable standard.

If you want to experiment with capabilities from the upcoming C++20 language standard, choose “ISO C++ Latest (/std:c++latest)” instead. Just note that support may be spotty or buggy.

Setting a language standard in Code::Blocks

Code::Blocks may default to a pre-C++11 language standard. You’ll definitely want to check and ensure a more modern language standard is enabled.

The good news is that Code::Blocks allows setting your language standard globally, so you can set it once (rather than per-project). To do so, go to Settings menu > Compiler:

Code::Blocks Settings > Compiler

Then find the box or boxes labeled Have g++ follow the C++XX ISO C++ language standard [-std=c++XX], where XX is 11, 14, or some other higher number (see the items inside the red box below for examples):

Code::Blocks C++11 setting

Check the one with the highest number (in the above image, that’s the C++14 option inside the red box).

Your version of Code::Blocks may also have support for upcoming (or just released) versions of C++. If so, these will be labeled Have g++ follow the coming C++XX (aka C++YY) ISO C++ language standard [-std=c++XX] (see the blue box above). You can optionally check these if you would like to enable features added in that version, but note that support may be incomplete (ie. some features may be missing).

See the list at the top of the lesson for a list of codenames to language standards mappings.

For example, if you want to enable C++17 capabilities and your settings doesn’t have a C++17 option, look for -std=c++1z (the code name for C++17).

Alternatively, you can go to the Other Compiler Options tab and type in -std=c++17.

Code::Blocks Other Compiler Options


This will work if your compiler has C++17 support. If you’re using an older version of Code::Blocks and C++17 features don’t seem to work, upgrade your compiler.

Setting a language standard in g++

For GCC/G++ users

For GCC/G++, you can pass compiler flags -std=c++11, -std=c++14, -std=c++17, or -std=c++2a to enable C++11/14/17/2a support respectively.

Testing your compiler

After you enabled C++17 or higher, you should be able to compile the following code without any warnings or errors.

If you can’t compile this code, you either didn’t enable C++17, or your compiler doesn’t fully support C++17. In the latter case, please install the latest version of your IDE/compiler, as described in lesson 0.6 -- Installing an Integrated Development Environment (IDE).

1.1 -- Statements and the structure of a program
0.11 -- Configuring your compiler: Warning and error levels

50 comments to 0.12 — Configuring your compiler: Choosing a language standard

  • Nick

    "ISO C++17 Standard (/std:c++17)" does not work for some reason. Is there any way to fix it?

  • ChickenShack

    Hello, I am currently doing every tutorial both with Visual Studio and Code Blocks. For both I have chosen C++17. Visual Studio worked fine but Code Blocks did not. When compiling I get the following error.

    g++.exe: error: unrecognized command line option '-Wsign-conversion-Werror'; did you mean '-Wsign-conversion'?

    I think it has something to do with the 'other compiler options' -Wsign-conversion-Werror but I dont actually know anything.

  • mode

    I have visual studio express 2017 and it give me 27 error and whan i try to change the standard there are no choices so i write /std:c++17 by myself and it give me 14 error  for example :
    E0283    qualified name is not allowed    HelloWorld    
    E0325    inline specifier allowed on function declarations only    
    E0135    namespace "std" has no member "string_view"    
    E0040    expected an identifier    HelloWorld        
    E0020    identifier "iNumbers" is undefined    
    E0017    expected a ']'    
    E1593    cannot deduce 'auto' type (initializer required)        

    it's distinctive error
    Element <LanguageStandard> has an invalid value of "/std:c++17".

    • yash

      exactly same thing is happening to me

    • nascardriver

      I can't find information about VS 17 express. The errors look like it doesn't support C++17. Use a newer visual studio.

      • mode

        what is a newer visual studio that need same Properties
        i mean there are differences between mine and newer because my lab top has 4 Gb Ram

        • nascardriver

          Visual Studio 2019 Community needs 2GB RAM minimum (, which is the same for VS2017, you can give that a try. Otherwise you'll have to use an IDE that isn't as memory hungry as VS, or even use an editor and compile manually.

  • sakib

    i can not run this in xcode

  • on #include <string_view> there is an error and ive updated code::blocks and it still won't work

    • nascardriver

      You have to update the compiler that code::blocks is using. See the big warning in lesson 0.6

  • Casey

    C++ newbie questions here. Is this supposed to happen in a new project? Should I just do this in the HelloWorld project? It does not seem to work in the HelloWorld project so I will try making it its own project but that is unclear.

    • abdelnour bentaieb

      no it should be fine to delete and paste the test program,as ffor why it s not working i found out that changing  disable language extensions to no under configaration properties->c/c++ -> language fixed the problem for me

      • nascardriver

        Don't enable language extensions. Enabling language extensions allows you to write non-standard code that doesn't work with other compilers. If the example code doesn't compile without language extensions, it means that your compiler doesn't support C++17.

  • Lifthra

    When you choosed the c++ language you did not use (all configuration), like you did for the errors, but Active(debug).
    What is the difference?

    • Alex

      My active configuration was the debug configuration, so this change would only impact my debug configuration. All configurations would make the change apply to both debug and release.

      You'd probably want to use All Configurations when changing your language standard since it wouldn't make sense to have debug compiled under one standard and release under another.

      I've updated the image to show All Configurations.

  • Daniel Jackson

    I am trying to run this program, after reinstalling the update for the compiler, and continue to get this message:

    ||=== Build: Debug in Learn C++ (compiler: GNU GCC Compiler) ===|
    D:\Programming Projects\Learn C++\Test 2.c|1|fatal error: iostream: No such file or directory|
    D:\Programming Projects\Learn C++\Testing Compiler.c|1|fatal error: array: No such file or directory|
    ||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

    • Daniel Jackson

      Never mind; found a transcription error; file did not have the correct extension. C++17 operational. Above program ran after I listened to the Debug Department.

  • prince

    Can you tell me what should be the result of the compiled program that you gave above

    • nascardriver

      The output doesn't matter. If you can compile the code, everything is working. Anyway

      • George Pitchurov

        It doesn't compile. Complains about #include <string_view>. I tried selecting future standard C++17, I tried putting a compiler option -std=C++17 and so on. I also upgraded gcc. I use codeblocks in linux Mint.

        • nascardriver

          You need at least gcc 7. You can check which version you have installed by running

          • Ben

            I'm having similar problems - compiler error messages:

            src/main.cpp:42:16: error: no viable constructor or deduction guide for deduction of template arguments of 'array'
                std::array arr{ 1, 2, 3 };
            /Library/Developer/CommandLineTools/usr/include/c++/v1/__tuple:223:64: note: candidate function template not viable: requires 0 arguments, but 3 were provided
            template <class _Tp, size_t _Size> struct _LIBCPP_TEMPLATE_VIS array;
            /Library/Developer/CommandLineTools/usr/include/c++/v1/__tuple:223:64: note: candidate function template not viable: requires 1 argument, but 3 were provided
            1 error generated.

            This is with Clang 10.0 on OSX - here is the output of clang --version:

            Apple LLVM version 10.0.0 (clang-1000.10.44.4)
            Target: x86_64-apple-darwin17.7.0
            Thread model: posix
            InstalledDir: /Library/Developer/CommandLineTools/usr/bin

  • Aditya

    I am using Code::Blocks, the 17.12 version and I got this error even after doing everything that is part of this tutorial,

    |3|fatal error: string_view: No such file or directory|

    Could it have anything to do with "..features added in that version, but note that support may be incomplete (e.g. some features may be missing)."
    What do I do??

    And also,
    Is it okay if I have zero knowledge of C++ before beginning these tutorials?

    • nascardriver

      The compiler you're using with code::blocks probably doesn't support C++17. There are currently no instructions for manually adding a compiler to code::blocks here.
      Googling for "code blocks C++17 windows" (Replace windows with your OS) should get you good instruction on how to add another compiler.

      Don't quit if you can't get it to work, you can still follow the majority of the tutorials with an old compiler.

      The tutorials are targeted at beginners, you don't need any prior programming knowledge.

  • Vitaliy Sh.

    Typo: two "[/note]"s is being visible near the end of the lesson.

  • Vitaliy Sh.

    Maybe your rather change "alt" to better fit the lesson's text: like a "CB: choose the stable/in-progress standard to follow" or smth?

  • Vitaliy Sh.

    Hi Sires!

    Empty "alt" attribute here.

  • Vitaliy Sh.

    (since it isn’t clear what year the standards will be finalized in until it actually happens).

    Maybe a typos (hard sentence to me):
    1) Maybe use "which" instead of "what"?
    2) No comma after "finalized in".

    Is my proposal from bad?

    • Alex

      1) Generally "which" is correct when we're selecting from a limited choice, and "what" is used otherwise. What seems like the better choice here, since we aren't given a discrete set of options.
      2) Fixed. Thanks!

      Your other proposal isn't bad, it just didn't seem to be to be better than what was already written.

      • Vitaliy Sh.

        ``No comma after "finalized in"'' isn't fixed, somehow.

        • Alex

          As far as I can tell, it shouldn't have one, per

          • Vitaliy Sh.

            Note that language standards use code names prior to the standards being finalized (since it isn’t clear what year the standards will be finalized in until it actually happens).

            Note that language standards use code names (instead of years) prior to the standards being finalized (since the year of finalization isn't clear until it actually happens).

            PS: (If someone can't connect to too: look up the or elsewhere).

  • Vitaliy Sh.

    to enable C++11/14/17 support respectively.

    Maybe add, just in case:
    The last "-std=" wins.

    g++ -std=c++03 -std=c++11 test.cpp
    g++ -std=c++11 -std=c++03 test.cpp

  • Vitaliy Sh.

    You can optionally check these if you would like to enable features in that version,

    Typo: either "in" instead of "from", or no "added" after "features".

  • Vitaliy Sh.

    C++ language standard [-std=c++XX]:, where XX is

    Possible typo: ":" before comma.

  • Vitaliy Sh.

        c++1x = C++11
        c++1y = C++14
        c++1z = C++17
        c++2a = C++20

    Possibly Typo: Capital "C" at right side from "=". Both g++ and clang++ are not accepted C++XX as a -std=.

  • Vitaliy Sh.

    Note that language standards use code names prior to the standards being finalized (since it isn’t clear what year the standards will be finalized until it actually happens).

    If apropriate, to:

    Note that prior to their finalization, the language standards are get referred by using the code names (since it isn't clear what year the standard will be finalized until it actually happens).

  • Vitaliy Sh.

    Generally, a compiler will pick a standard to default to (often not the most recently language standard).

    Typo: either no "published" between "recently" and "language", or "recently" like to be "recent".

    Maybe also change to:
    Generally, the compiler will pick a default one (which is often ...

  • Aymen Chehaider

    Nice tutorial Alex. Could you post some guidelines / steps on how to use the last compiler using MSYS2. Iknow that it may be out of scope or can find some clues by googling but will appreciate any stuff on how to configure MSYS2.

    Thank you in advance

Leave a Comment

Put all code inside code tags: [code]your code here[/code]