我在 VS Code 中使用了 C++17。现在我想使用C++20或C++23,但我无法从C++17版本更改。
我尝试了很多方法,比如在Task.json中添加“-std-c++2b”或者将C++Standard设置为C++23,但我的VS Code仍然是C++17。也许我重新安装了 VS Code 并重新设置了?
在 VSCode 项目中浏览
.vscode
文件夹,然后在 tasks.json
中键入类似以下内容(根据您的版本需求进行调整):
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "g++",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
"-std=c++23" // Add this line for C++23
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
还尝试配置
c_cpp_properties.json
:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.18362.0",
"compilerPath": "C:/MinGW/bin/g++.exe",
"cStandard": "c17",
"cppStandard": "c++23" // Change this line for C++23
}
],
"version": 4
}
最后重建你的项目。它应该对你有用。