我正在尝试设置 Visual Studio 代码以使用 C++ 编程。我已经安装了扩展 C/C++ 和 C/C++ Intellisense
以下是我的代码:
#include<iostream>
using namespace std;
int main()
{
cout<< "hello" ;
}
我得到的错误是 identifier cout is undefined
当我把它写成 std::cout
我得到的错误是 namespace std has no member cout
。以下是我的 task.json
文件:
{
"version": "0.1.0",
"command": "make",
"isShellCommand": true,
"tasks": [
{
"taskName": "Makefile",
// Make this the default build command.
"isBuildCommand": true,
// Show the output window only if unrecognized errors occur.
"showOutput": "always",
// No args
"args": ["all"],
// Use the standard less compilation problem matcher.
"problemMatcher": {
"owner": "cpp",
"fileLocation": ["relative", "${workspaceRoot}"],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
}
]
}
我该如何解决?
原文由 Nirvan Anjirbag 发布,翻译遵循 CC BY-SA 4.0 许可协议
它是一个 错误。
这个错误有一个解决方法,在 VS Code 中转到
File -> Preferences -> Settings
并更改"C_Cpp.intelliSenseEngine": "Default"
到"C_Cpp.intelliSenseEngine": "Tag Parser"