Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I upgrade to C++17?

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).

like image 683
yellowgrass Avatar asked Jul 21 '20 04:07

yellowgrass


People also ask

What is STD C ++ 17?

C++17 is a version of the ISO/IEC 14882 standard for the C++ programming language. C++17 replaced the prior version of the C++ standard, called C++14, and was later replaced by C++20.


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.

like image 169
Jorengarenar Avatar answered Oct 16 '22 18:10

Jorengarenar


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.

like image 25
Rohan Bari Avatar answered Oct 16 '22 18:10

Rohan Bari