C++ has multiple language standards: C++98, C++03, C++11, C++14, C++17, C++20, C++23, and newer standards in progress.
When you configure a compiler, you are not just choosing “C++.” You are choosing which version of the language the compiler should accept. That decision affects which syntax, library features, and diagnostics are available to your program.
Three things to take away:
- The language standard controls which version of C++ your compiler uses.
- Newer standards provide more features, but compiler and library support may lag.
- For learning and portfolio projects, C++20 is often a strong practical defaul
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.
Setting the standard with g++
With GCC or Clang, the language standard is usually selected with the -std= flag.
For C++20:
g++ -std=c++20 main.cpp -o main
If no standard is specified, the compiler uses its own default. That default can vary by compiler version, so it is better to be explicit.
A build command like this is clearer:
g++ -std=c++20 -Wall -Wextra -Wconversion main.cpp -o main
Now the build says exactly which version of C++ is expected.
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"
],
This tells g++ to compile the active file using the C++20 language standard.
Configuring IntelliSense
VS Code has two related systems:
- The compiler that actually builds your program.
- IntelliSense, which powers editor features such as autocomplete and squiggles.
If the compiler uses C++20 but IntelliSense is configured for C++14, the editor may incorrectly mark valid code as invalid.
Navigate and open 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
}
Takeaway
The C++ language standard controls which version of the language your compiler accepts. Setting the standard is important since each revision introduces new features.
Do not choose a standard randomly, and do not assume the newest option is automatically best.