作者最近在ubuntu上开发C++,但经常看到vscode identifier “xxx” is undefinedC/C++(20)这样的问题。比如今天:
identifier "thread" is undefinedC/C++(20)
但,明明可以点击thread进去,查看头文件。
只不过,这部分是灰色的。然后往上翻,发现了问题所在。
点到这里可以发现,__cplusplus这个宏是199711L,确实小于201103L.
解决办法如下:编辑configuration.json
可以看到,cpp的标准是98的。那么修改成11.
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu11",
"cppStandard": "gnu++11",
"intelliSenseMode": "linux-gcc-x64"
}
],
"version": 4
}
然后就OK了