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

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

  • Zatch

    one.cpp:9:27: error: 'string_view' in namespace 'std' does not name a type
        9 |     inline constexpr std::string_view str{ "hello" };
          |                           ^~~~~~~~~~~
    one.cpp:9:22: note: 'std::string_view' is only available from C++17 onwards
        9 |     inline constexpr std::string_view str{ "hello" };
          |                      ^~~
    one.cpp: In function 'std::tuple<unsigned int, typename std::common_type<_Tp>::type> sum(T ...)':
    one.cpp:15:36: warning: fold-expressions only available with '-std=c++17' or '-std=gnu++17'
       15 |     return { sizeof...(T), (args + ...) };
          |                                    ^~~
    one.cpp: In function 'int main()':
    one.cpp:20:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
       20 |     auto [iNumbers, iSum]{ sum(1, 2, 3) };
          |          ^
    one.cpp:21:27: error: 'str' is not a member of 'a::b::c'
       21 |     std::cout << a::b::c::str << ' ' << iNumbers << ' ' << iSum << '\n';
          |                           ^~~
    one.cpp:23:16: error: missing template arguments before 'arr'
       23 |     std::array arr{ 1, 2, 3 };
          |                ^~~
    one.cpp:25:23: error: 'size' is not a member of 'std'
       25 |     std::cout << std::size(arr) << '\n';
          |                       ^~~~
    one.cpp:25:28: error: 'arr' was not declared in this scope
       25 |     std::cout << std::size(arr) << '\n';

    this is happening in visual code (updated ) can't understand how to fix it

    • nascardriver

      "fold-expressions only available with '-std=c++17' or '-std=gnu++17'"
      You didn't enable C++17 support. Look up how to add compiler flags with the C++ extension you're using.

  • AQL

    helloworld.cpp:23:16: error: no viable constructor or deduction guide for
          deduction of template arguments of 'array'
        std::array arr{ 1, 2, 3 };
    /Applications/ note:
          candidate function template not viable: requires 0 arguments, but 3 were
    template <class _Tp, size_t _Size> struct _LIBCPP_TEMPLATE_VIS array;
    /Applications/ note:
          candidate function template not viable: requires 1 argument, but 3 were
    1 error generated.

    whats wrong?? i am using g++ in macos terminal and am using -std=c++17 flag

    • nascardriver

      g++ can compile this code since version 7.3
      Either you're using a very outdated version of g++ or you're not passing it the -std=c++17 option correctly.
      What's the output of `g++ --version`?
      How are you invoking g++ to compile your file?

      • AQL

        Configured with: --prefix=/Applications/ --with-gxx-include-dir=/usr/include/c++/4.2.1
        Apple LLVM version 9.1.0 (clang-902.0.39.2)
        Target: x86_64-apple-darwin17.7.0
        Thread model: posix
        InstalledDir: /Applications/
        This is the output of g++ --version
        i am very new at this so i don't know what should i do
        is this the latest version??

        • nascardriver

          You're using apple clang, not g++. I don't know why g++ is an alias for apple clang on your system.
          Apple clang is supposed to support the feature that's causing your error, but obviously it doesn't.
          9.1.0 is not the latest version of apple clang, there is at least version 11.

          The first thing you should try is updating your apple clang. If that doesn't work, install the real g++.
          I can't assist you with either of those, I don't know how apple things work.

  • SupurituMeatu

    can you guys add commentary of this code so I can understand what exactly is happening there? thanks :)

    • nascardriver

      You're not supposed to be understanding this code. It's sole purpose is to check if your compiler is set up correctly.
      You can come back here when you're done with the tutorials to learn more about the language (learncpp doesn't cover all features used in this snippet).

  • Jeremiah Xu

    Here is the test code I could run on my Xcode(version:9.2) with c++==17.
    The only difference from the original test code is that I add '<int, 3>' after 'std::array'. So I am wondering whether this is a typo or not.(maybe this is the attribute we should assign to the array?)

    • Jeremiah Xu

      It seems that I am still using c++11(reference: So does anybody fix this in Xcode 9.2?

      • nascardriver

        This looks very odd to me. As I said in the other comment, I don't know which compiler you're using, but this should probably be

    • nascardriver

      Since C++17, the `<int, 3>` is is optional. If your compiler requires it, it's lacking some C++17 features.

      According to cppreference, Apple Clang (Which is what I suppose Xcode uses) supports class template argument deduction (Which is what allows the omission of `<>`).

      I don't know which compiler Xcode uses, I don't know which version you have or need, and I don't know how Apple handles updates, so I can't assist you any further. If you find a solution, please post it here for the next person who encounters the issue.

      • Jeremiah Xu

        I am using macOS 10.12 and my clang version is 9.0.0; so maybe I could not use the template argument deduction(when I use 'brew install llvm' to upload my Apple llvm it just said my mac version is too low.)

    • Jeremiah Xu

      I have fixed this problem by updating my macOS to macOS Catalina. I am using Xcode 11.1 now. Here is a \href{}{XcodeVersionInfo} website for reference on choosing which version of Xcode to be used on your macOS system.

  • Anonymous

    I want to turn off the dropdown list that you get beside your cursor with suggestions every time you try to type. I am using Visual Studio Community 2019 latest version (downloaded yesterday).

    What is the best way to do that such that other settings aren't affected?

  • sam p

    Just to say a special Thanks for all this "compiler configuration" stuff - super useful, but have never seen this covered anywhere else. Much appreciated.

  • Nick

    So I decided to try copying my warnings (which I got from your guide) from Code::Blocks to Visual Studio Code, which I prefer using and have been using just fine before. However, after attempting to run the test file to make sure my warnings/compiler settings were getting along, I ended up getting this:

    My Language Standard is set to c++ 2017, and my warnings are:

    Again, these settings worked FINE in Code::Blocks, but not with VS Code which is my preferred program. I actually use both just to become more familiar with C++ in VS Code while following this and other classes/tutorials in Code::Blocks, then copying the main.cpp over into VSC, and Build/Debug all over again, so that it exists in both of my C++ Project File directories respectively. Never had any conflicts between the two.

    Until I know how the F*** to fix it, I suppose I'm just going to have to disable my warnings, as I have had 0 issues with this tutorial and compiling programs prior to adding those special arguments.

    • nascardriver

      Those are errors, not warnings.

      VSCode isn't an IDE so configuring it can be a little harder than configuring an IDE.

      VSCode tries to detect your compiler and compiler settings. Depending on how you're compiling, it may or may not find them. It sounds like you're compiling successfully with VSCode, which means VSCode is using a different compiler/settings to perform error-checking than you're using to compile.

      Read the instructions of your C++ plugin figure out how to set it up properly.

      • Nick

        EDIT: Just to make sure it still DOES work when compiling with Code::Blocks, I made sure to have the compiler in C::B set as C:/codeblocks/MinGW, as I did notice that previously Code::Blocks had been using the SAME COMPILER AS VISUAL STUDIO CODE THE WHOLE TIME, and it would still work inside Code::Blocks. Hopefully that bit of info might be helpful in figuring out this stuff haha. So that must mean something just... isn't set right (probably exactly what you said)? This has to narrow it down to something in visual studio code's configuration right?

        Sorry, errors. I was using "warnings" and "errors" interchangeably, however I do understand the difference.

        The problem is I am NOT compiling successfully correct...? I cannot get past the initial Building process with this program. I just get those same errors. I've gone through every configuration file I have, all of them are set to the correct compiler I installed, C:/mingw/bin/g++.exe. Intellisense set to gcc-x64, debugger as gdb. All within the same c:/mingw root folder. I copied the *exact same git repo used IN the tutorial given by VS studio Code themselves that they said to copy, and made sure everything matched up*.

        I don't want to have to use seperate programs, just because ONE language's settings are totally messed up apparently unbeknownst to me before trying to compile this god-forsaken "test". Downloading Visual Studio 2019 may be my only option, or I suppose I could try to reinstall everything for the third time, but I honestly am beginning to fail to even see the purpose. Everything has been going just fine up until this compiler test; it seems silly to start reinstalling a bunch of things or just getting STUCK because I can't compile this test file or figure it out.

        This issue alone has caused me to lose so much motivation and drive in regards to wanting to challenge myself and keep learning C++, and cranked the "imposter syndrome" knob to 11. When things are moving along well in all of my classes, but then I find out that I apparently can't even set up my compilers correctly and I might be learning "bad practice", it really bothers me, and I don't want to move forward with my education in C++ until I can solve this issue or just give up for a few years and just keep learning the other languages I'm working on.

        • nascardriver

          From your original post

          Your g++ doesn't know C++17, only an in-dev version of it. Because it's in-dev, it's not called -std=c++17 but -std=c++1z. If you told your vscode plugin to use C++17, it might be setting -std=c++17, which your compiler doesn't understand. The best fix for this is upgrading your compiler. If you can't upgrade for a good reason, try telling your vscode plugin to use c++1z.
          CodeBlocks, being an IDE, knows what you compiler supports, so it will make such a change without you knowing about it.

          It's best you seek help in the forum/issues of the C++ plugin for vscode you're using. I can only guess.

          • Nick

            Edit: For some reason, "plus signs" will not display in my comment. Any strange blank spaces in the following should be assumed to be plus symbols:

            So after even MORE fiddling around and experimenting, I eventually just tried typing "-std=c  1z" next to the other normal commands that automatically run when I click "run code" and - MY GOD....... IT WORKED!!!!!

            I have literally put my Cpp  education on hold for exactly ONE MONTH just because of this compiler (pardon my language, but it is what it is-) BULLSHIT. Now no matter what I modify in the configs, I cannot get VS Code to include "-std=c  17" along with its other commands. So for now, all i can do is MANUALLY TYPE "-std=c  17" before EVERY SINGLE TEST RUN. It's mind boggling how unintuitive this fucking app is. I've given myself so much punishment and trouble over this trash.

            Now all I have to do is figure out how to tell VS Code to include "-std=c  17" next to the other commands exactly like this:

            c:\Users\Me\Desktop\C  \VS Code\Visual Studio C  \Projects\CompilerTEST>cd "c:\Users\Me\Desktop\C  \VS Code\Visual Studio C  \Projects\CompilerTEST\" && g   -std=c  1z CompilerTest.cpp -o CompilerTest && "c:\Users\Me\Desktop\C  \VS Code\Visual Studio C  \Projects\CompilerTEST\"CompilerTest

            ...and thats IT. That will literally solve the GD problem that's caused so much frustration for me.

  • Max

    When I paste it into visual studio code I get 15 errors

    qualified name is not allowed

    inline specifer allowed on function declarations only

    namespace “std” has no member “string_view”

    expression must have a constant value

    expected an identifier

    identifier “iNumbers” is undefined

    expected a ‘]’

    cannot deduce ‘auto’ type (initializer required)

    expected a ‘;’

    name followed by ‘::’ must be a class or namespace name

    argument list for class template “std::array” is missing

    expected a ‘;’

    no instance of overloaded function “std::size” matches the argument list

    identifier “are” is undefined

    “Yes (/EX)” is an invalid value for the “TreatWarningAsError” parameter of the “CL” task. The “TreatWarningAsError” parameter is of type “System.Boolean”.

    • Noah

      I'm getting the same errors. Any luck on your end?

      • Hanayou

        Hey guys,

        You probably figured this one out already but for me this was because when I opened my project properties window my platfrom (drop down at top of window next to configuration) was always pre-selecting x64, despite the fact when clicking on the drop-down the Active platform was shown to be Win32.

        Change your selection on here to be Win32 OR All Platforms and once again set the langauge standard to C++17 (and any other settings such as compiler warning level, language extensions etc. as these are set per platform)

    • Nick

      Same shit here, except I'm getting 7 errors. This is so frustrating. Everything was working fine in both my Code::Blocks and VS Code, and I was even copying and pasting my .cpp files between the two, just to compile and build my programs using BOTH, just so I can keep using my preferred editor VSC and get used to it.

      Well OH FUCKING SHIT, here comes this goddamn "example" and now I'm just totally stuck. What in the hell. I've made sure everything links to the SAME c:/mingw/ root folder, and compared my settings with the GIT REPO YOU CAN COPY AND USE FROM THE VS CODE TUTORIAL ITSELF to set it up, and it STILL doesn't work. I am so done with this.

  • Abbas

    I copied and pasted the code and compiled with the command: 'g++ -g test.cpp -o test -pedantic-errors -std=c++17 -Wall -Weffc++ -Wextra -Wsign-conversion'
    The code compiles and runs with no errors, but it gives me 3 warnings and I cannot figure out what the problem is.

    The warnings are:

    1. expression must have a constant value -- cannot call non-constexpr function "std::char_traits<char>::length" (declared at line 403 of "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\iosfwd")

    2. no instance of constructor "array" matches the argument list -- argument types are: (int, int, int)

    3. no instance of overloaded function "std::size" matches the argument list -- argument types are: (<error-type>)

    my g++ version is 9.2.0

    The code is:

    Thanks for any help

    • nascardriver

      The "warnings" you quoted are errors. The program that caused these error is unable to compile your code. I suppose you're compiling with g++ but are using a different compiler (Or at least different settings) in your editor/IDE.

      • Abbas

        Thank you for the help.
        I was using Visual Studio Code, and compiling by typing the command in the terminal. VS Code prompted me to install a recommended C/C++ extension that added intellisense and debugging tools for C++ coding.

        Disabling that addon fixed the problem for me. Thank you

  • bc0054

    I found this useful for xcode

  • MrGeeBee

    Using MS VS 2019 and have followed the steps to set it up, but on this line:

    It tells me "no operator "<<" matches these operands operand types are: std::basic_ostream<char, std::char_traits<<char>> << std::common_type<int, int, int>

    No other warnings

    My code:

  • Aptenodyte

    I have followed the instructions to set the C++ standard for Visual Studio, and have copied in the testing code exactly as it was given. However, when I try and build the project, I get the following error:

    • Aptenodyte

      Ah, never mind, I realized I accidentally selected the template for a windows desktop application as opposed to the windows desktop wizard. After selecting that correctly, the example worked fine.

  • Aidan Robbins

    Hey there,
    I'm trying to run the example code that was given and it is just saying in the build info thing that it is up-to-date. The hello world program went fine, and I've done all the configurations. Help would be appreciated.

  • Gage

    Hello I am getting errors on the test code
    I have the Version and setting as listed above and downloaded virtual studio as the tutorial shows. Not sure what to do to fix the problem

  • What IDE's do you recommend to use in Ubuntu, I tried CodeBlocks but it have worst UI.

  • The given sample code for testing c++17 compiles and runs without any issues, but my eclipse CDT says -

  • Ahmed Sersawy

    Thanks for a remarkable effort........

  • Rafael`

    Waiting for VS code ide.

  • Dhruv

    I have changed my settings from c++20 to c++17 because the test code is not working at c++20 in code block

    • nascardriver

      The test code is compatible with C++20. Your compiler probably doesn't know what C++20 is so it fell back to a version before C++17.

  • Judestadt

    Is there any difference between 'using namespace std' and writing std:: in every line of code? Which one is better to be accustomed to?

    • Ro

      In my experience, it depends on the use case. If you are using std functions a lot, it would be a good idea to use the namespace to save time writing.

    • Hello Judestadt,
      The statement using namespace std is generally considered bad practice. The alternative to this statement is to specify the namespace to which the identifier belongs using the scope operator(::) each time we declare a type.

      Read full article here -

  • brokenVectors

    Instead of << '\n', couldn't we do std::endl?

  • Jim177

    How do I start another program in C::B 20.3 after I'm done with the "Hello World! program. It keeps showing up in the management window on the left C::B screen.   Do I need to start a new project or a new file. I'd like to keep all my old programs as a cross reference for future programs.  I keep getting back into the Hello World program for some reason.  I would think it would be better to us a file for each new program.

    • Jim177

      I may not have my C::B compilers setting set right. I'm using GNU GCC Compiler (x64)

      Under the compiler flag tab, I deleted the (Wsign-conversion -werror) because I was getting a red warning at the bottom of build log. But I still have the first three warnings turned on. Along with an Intel Cor w 64 bit extension. I'm using -std+c++2a for C++20.

      Please help.  I

      • Dhruv

        1st stop using compiler extension and then set the compiler version to -std=c++17 from c++20.
        you can add Wsign-conversion -Werror in other compiler tab . it will work fine.

  • Jim+Guth

    I need some help with my editor in C::B 20.3 and Windows 10. If I try typing in the middle of one of my lines of code the character that follow are overwritten, so I can't  modify or add things to any part of the line.

    There must be a C::B editor setting to fix this but I don't now how?  Please help Thanks

    It would also be helpful if you created a section on using different editor commands, like I know CTRL+ D will copy the line where the cursor is.

    • Jim+Guth

      Fixed used the insert key in the home group above the arrow keys.  The ins key in the numbers doesn't do the trick.  You can delete my post if you'd like.

  • evolve

    Is there any way to install c++17 in Visual studio code? I am using macos.

  • Maurizio

    I use now Code::Block 20.03 under Linuxmint 19.3.
    There are for every C++ version two choices in the compiler settings: GNU or ISO
    Somebody knows the difference between using -std=gnu++17 or -std=c++17 ?
    The tests were successful with both parameters but the output file is a bit smaller using -std=c++17. Googling was not really a help.

    • nascardriver

      gnu++ enables language extensions. Language extension are evil.

      • Maurizio

        Thanks a lot. I googled about what language extentions are and why it's evil. That convinced me.

      • Maurizio

        With Language extentions do you mean QT or GTK+ as well?

        • nascardriver

          QT and GTK+ are libraries, not extensions. Language extensions change the language itself, something that can't be done without modifying the compiler. For example

          would create a temporary array. This looks like it could be C++, but it isn't. It only works if the compiler has an extension for it.

  • DanJ

    I would like to note, that going through tutorials, and having to update the compiler each time to make sure you are on the latest is a bit annoying. For anyone wanting to make this process easier in VS2019, I recommend you set up a template.

    You can see how to do that here:

    Simply set the settings you want, export it as a template, then whenever you start a new project you can use that as the template. Don't worry, it still asks you to create a new project like normal, it just uses that templates settings! As you get more advanced, you can update that template to cater to your needs.

  • David B

    Hey, I'm using codeblocks and I'm pretty sure I've done everything I'm supposed to. But the test code will not compile

    This line gives the error: 3    fatal error: string_view: No such file or directory.

    I reinstalled the latest version of codeblocks. (The one recommended in a previous lesson) But I still have this issue.

    Is there anything I can do? :/

    • David B

      Anyone know what I can do?

    • nascardriver

      Your compiler is too old. In this table, you can see which version of your compiler you need at least. Codeblocks 20 should come with a compatible compiler.

      • David B

        My codeblocks version is 20.03 (I updated to at least what I think is the latest when it didn't work the first time.)
        Which is why i'm sort of confused. Is there a newer version somewhere else?

        • nascardriver

          codeblocks 20.03 is the latest version, but you might have installed an old compiler anyhow. In codeblocks, go to
          settings -> compiler -> toolchain executables
          There you can see which compiler you're using. Get the version of that compiler, eg.

          if you're using clang and the installation directory is /usr

          Then check the table I liked above so see if the compiler is too old, which it probably is. If it is too old, install a newer compiler and select it in codeblocks. If your compiler is not too old, something else is wrong.

          • David B

            I had a look at the toolchain executables tab and realised it was still using the old compiler from my previous codeblocks install. It runs the code fine now. Thank you so much for the help!

  • Niranjan Bala

    In the code names section, where code names are mapped with the final names, 'c++1x' is mapped with 'c++11'. But the actual code name was supposed to be 'c++0x' there, since it was expected to be published before 2010. Please correct me if I am wrong.

Leave a Comment

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