-1

I am setting up the environment to learn C++. I am using VS Code as an IDE and MinGW as a Compiler. but it

seems that i can't run C++17 code without alot of errors. So i used the following code to check C++ version

#include<iostream>
int main() {
if (__cplusplus == 201703L)
  std::cout << "C++17";
else if (__cplusplus == 201402L)
  std::cout << "C++14";
else if (__cplusplus == 201103L)
  std::cout << "C++11";
else if (__cplusplus == 199711L)
  std::cout << "C++98";
else
  std::cout << "pre-standard C++";
}

it returns C++14. I googled it but ended up with "Change your IDE" which i cant because i have a very low end Laptop which can bearly handle VS Code without screen freezing. I have also seen the "g++ -std=c++17 file.cpp" tip which didnt work either. I would appreciate it if someone can help me without changing the IDE.

(i have also downloaded the C++ package from the Microsoft Visual Studio installer which was around 6GB and used "CL" as a Compiler in VS Code but it returns C++98 when running the above code for some reason.)

Leon
  • 1
  • 2
  • It looks like you may need to run the Visual Studio installer(I can't remember if the VS installer was also used to install VS Code - I currently use both) to install C++ 17. https://code.visualstudio.com/docs/cpp/config-msvc – Skewjo Feb 17 '21 at 17:21
  • How does your VSCode task configuration JSON file look like? Did you specify the `-std=c++17` compiler flag there? – πάντα ῥεῖ Feb 17 '21 at 17:21
  • Does this answer your question? [How to enable C++17 support in VSCode C++ Extension](https://stackoverflow.com/questions/49397233/how-to-enable-c17-support-in-vscode-c-extension) – πάντα ῥεῖ Feb 17 '21 at 17:30
  • Please add the version of g++ provided by your mingw installation. You should be able to get this by invoking g++ on the command line with the -v option. If this returns something in the 6s or 7s you'll want to update the compiler. – user4581301 Feb 17 '21 at 17:31
  • @Skewjo i followed that exact tutorial which didn't help. – Leon Feb 17 '21 at 19:07
  • @πάντα ῥεῖ i thought that line can be used in the cmd only, Can you clarify more on how can i adjust my task.json file to adabt ? – Leon Feb 17 '21 at 19:08
  • My G++ version is 8.1.0 – Leon Feb 17 '21 at 19:09
  • The link unfortunately didn't help. – Leon Feb 17 '21 at 19:15

1 Answers1

0

Check out this page __cplusplus conformance. By default, the compiler MSVC always define the macro __cplusplus to 197711L, thus it does not conform to the standard. Add the flag /Zc:__cplusplus explicitly to enable the conformant behaviour. Not that the /permissive- does not affect the /Zc:__cplusplus flag implicitly (contrary to most other conformance /Zc flags).