As part of configuring our compiler, we can select the language standard or version. Recall that various versions exist including C++98, C++03, C++11, C++14, C++17, C++20, C++23.
Which language standard should you choose?
Whilst you might think to choose the latest standard, it’s recommended to choose a version that is 1-2 versions older than the latest.
This allows the compiler manufacturers iron out defects and provide excellent support for that standard.
This also helps ensure better cross-platform compatibility, as compilers on some platforms may not provide full support for newer language standards immediately.
Changing C++ standard on VSCode
Navigate to tasks.json.
Place the appropriate language standard flag (including the double quotes and comma) in the args section, on its own line before ${file}. See below
// tasks.json
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\\\msys64\\\\ucrt64\\\\bin\\\\g++.exe",
"args": [
"-std=c++20", // Insert it here
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\\\${fileBasenameNoExtension}.exe"
],
// ...
Let’s also configure IntelliSense to use the same language standard. Go to c_cpp_properties.json. This is the file to configure IntelliSense.
Update the cppStandard key
// c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:\\\\msys64\\\\ucrt64\\\\bin\\\\gcc.exe",
"cStandard": "c23",
"cppStandard": "c++20", // Update this line
"intelliSenseMode": "windows-gcc-x64"
}
],
"version": 4
}