1

I'm running g++ compiler on windows 10 with mingw. On checking compiler version in cmd I get the following:

g++ --version- g++ (MinGW.org GCC Build-2) 9.2.0

same with c++ --version

When I compiled a cpp program making use of structured bindings I got a warning:

warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'

But otherwise the code ran fine. Does everyone get this warning or am I running a lower version compiler?

I'm using an extension - Competitive programming helper, and this warning interrupts the process. Hence, if it is the case that everyone gets this warning, is there a way I can block version specific warnings only without having to block all compiler warnings.

TIA.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
Karmah24
  • 485
  • 1
  • 5
  • 14
  • 4
    The compiler picks a different default standard than C++17. Hence, you have to manually pass `-std=c++17` as a command line flag (or configure your build accordingly). See [this thread](https://stackoverflow.com/questions/44734397/which-c-standard-is-the-default-when-compiling-with-g) on how to find out about the actual standard by default. – lubgr Aug 07 '20 at 10:36

1 Answers1

4

As the warning itself says:
structured bindings only available with '-std=c++17' or '-std=gnu++17'.
Meaning, you are using cpp version 14 or lower as compiler. However, you also have cpp 17 or higher installed on your system to get such kind of warning.
Your program will still run but with the warning.
For Windows:
If you are using VS code (assuming that you are already using code runner) then,

  1. Open Settings(UI) of VS code (Ctrl + ,)
  2. Search for Code-runner: Executor Map
  3. Click on Edit in settings.json
  4. Something like this will appear:
    enter image description here
  5. In cpp section: change it to "cd $dir && g++ -std=c++17 $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt" as in the picture above.

It is finally done now.

Below steps are for linux.

  1. Open .bashrc file using command sudo gedit ~/.bashrc in terminal.
  2. In the .bashrc file, add
    alias g++="g++ --std=c++2a" at the end of the file.
    This will always compile your file in cpp+20 version.

Once done, you will not get any warning.
Note: It is not mandatory to use cpp+20. You can use any version you like.
Change the version according to this website
https://www.learncpp.com/cpp-tutorial/configuring-your-compiler-choosing-a-language-standard/