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

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

  • kirozin

    Trying out the code in Visual Studio 2019, I received fatal error c1010, which after googling found that I needed to simply add "#include <pch.h>" before any of the other header files. And when I did that, c1010 disappeared, but I still got error e1696. Am I doing something wrong?

    Edit: I turned off precompiled headers and this seems to have worked. Please let me know if this is a good fix for future issues.

  • J Nava sai krishna

    For Codeblocks users: I think even if we checked the box +20 version(latest) it gives an error. we need to swtich back to +17 version as instructed by the author
    Also It clearly gave an error where I need to fix my changes.

    "The compiler's setup (GNU GCC Compiler) is invalid, so Code::Blocks cannot find/run the compiler.
      Probably the toolchain path within the compiler options is not setup correctly?!
      Do you have a compiler installed?
    Goto "Settings->Compiler...->Global compiler settings->GNU GCC Compiler->Toolchain executables" and fix the compiler's setup.

    Tried to run compiler executable 'C:\Program Files\CodeBlocks\MinGW\lib\gcc/bin/gcc.exe', but failed!

    Nothing to be done (all items are up-to-date)."

    as mentioned in the error i tried to auto detect the compiler option in the tool chain executables then it got resolved. Hope anyone facing the same error can get help with this
    have a great day

  • Ivan

    I'm using Visual Studio 2015 and I don't have the option to choose language standard.And I can't compilethe codes.

  • Aarmaan

    when I tried to complie i got this

    'HelloWorld.exe' (Win32): Loaded 'C:\Users\Aarmaan\Desktop\c++ Projects\HelloWorld\Debug\HelloWorld.exe'. Symbols loaded.
    'HelloWorld.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ntdll.dll'.
    'HelloWorld.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel32.dll'.
    'HelloWorld.exe' (Win32): Loaded 'C:\Windows\SysWOW64\KernelBase.dll'.
    'HelloWorld.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcp140d.dll'.
    'HelloWorld.exe' (Win32): Loaded 'C:\Windows\SysWOW64\vcruntime140d.dll'.
    'HelloWorld.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ucrtbased.dll'.
    The thread 0x35d8 has exited with code 0 (0x0).
    'HelloWorld.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel.appcore.dll'.
    'HelloWorld.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcrt.dll'.
    'HelloWorld.exe' (Win32): Loaded 'C:\Windows\SysWOW64\rpcrt4.dll'.
    'HelloWorld.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sspicli.dll'.
    'HelloWorld.exe' (Win32): Loaded 'C:\Windows\SysWOW64\cryptbase.dll'.
    'HelloWorld.exe' (Win32): Loaded 'C:\Windows\SysWOW64\bcryptprimitives.dll'.
    'HelloWorld.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sechost.dll'.
    The thread 0x4b48 has exited with code 0 (0x0).
    The thread 0x2848 has exited with code 0 (0x0).
    The thread 0x2308 has exited with code 0 (0x0).
    The program '[6704] HelloWorld.exe' has exited with code 0 (0x0).

  • angel


    what i'm supposed to get?

  • violist

    In Linux Ubuntu you have to use g++ -std=c++17 nameofthefile.cpp to compile it and than ./a.out. If you use standard g++ nameofthefile.cpp you will get errors because standard g++ doesn't support c++17.
    If you want to automatically compile and run program let's say in sublime text, create a new build system, add this in it and save it:

       "cmd": "g++ \"${file}\" -o \"${file_path}\\\\${file_base_name}\"",
       "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
       "working_dir": "${file_path}",
       "selector": "source.c,source.c++,source.cpp",
       "variants": [
           "name": "Run",
            "cmd" : ["gnome-terminal -- bash -c \"g++ -std=c++17 $file_name; ./a.out;echo;echo;  echo Press ENTER to continue; read line;exit; exec bash\""

  • Mike

    I compiled the code, but I don't know what it means, for example "#include".
    Later on will he teach?

    • LoneWoIf

      He surely will... This code is just designed to test if your compiler is fit to compile language features from C++17. You will learn about all those language features later.

  • Cuyler

    In Visual Studio 2019 Community, should I use /std:c++17 or /std:c++latest? I know I'm supposed to use the most up-to-date version, but I'm getting the impression that /std:c++latest might not be a full release or something.

  • yobro

    i got a whole mess off errors

  • micuaderno

    i got this error by testing compiler

    Severity    Code    Description    Project    File    Line    Suppression State
    Error    LNK1168    cannot open

  • orb

    i get an error unrecognised command line option -wsign-conversion-werror did u mean wisgn-conversion

  • TimT

    There needs to be something about setting the solution platform in Visual Basic. I'm using the latest version, and the example code here wouldn't compile until I set the platform to 'X64' on the compiler toolbar and in project properties.

  • don

    could i use sometimg like c++20

  • TheRote

    I get an error with "arr" in line 23 it says "undeclared identifier"

  • fox

    i pasted the code into visual 2019 in c++17 but its not working
    what can i do?

    edit im such a doofus ive gone to general instead of languages
    my bad sorry

Leave a Comment

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