How do I upgrade to C++17?

Viewed 23274

I am using Atom as my IDE, my current __cplusplus = 201402 which is C++14 and my compiler is g++ (GCC) 9.2.0.

How do I upgrade to C++17 or C++20?

Everything I've searched up involves using another IDE (Microsoft Visual Studio).

2 Answers

You don't "upgrade" to newer C++ standards.
You can upgrade compiler to newer version supporting latest standards.

As of today, most compilers are set to C++14 by default.
To change it you need to pass additional argument during compilation.

For example, to compile hello.cpp with GCC for C++17 you need to execute

g++ -std=c++17 hello.cpp

You need to check how to pass compiler flags (or set standards) in your IDE / editor / build system.


I'm not familiar with Atom, but I've found this:

In the settings, click on Packages, then search for gpp-compiler. You should see a settings button – click on it and edit the command line options to suit your needs.

Do-it-yourself:

#include <iostream>

int main(void) {
    std::cout << __cplusplus;

    return 0;
}

Compile this firstly with the following command:

$ g++ -o main main.cpp && ./main

Thereafter:

g++ -o main main.cpp -std=c++17 && ./main

You'll get to know the differences. Note that if you're unable to use -std=c++20 flag, it clearly means that your compiler doesn't supports C++20 standard.

Related