为什么 Visual Studio 代码告诉我 cout 不是 std 命名空间的成员?

新手上路,请多包涵

我正在尝试设置 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 许可协议

阅读 2.2k
2 个回答

它是一个 错误

这个错误有一个解决方法,在 VS Code 中转到 File -> Preferences -> Settings 并更改

"C_Cpp.intelliSenseEngine": "Default""C_Cpp.intelliSenseEngine": "Tag Parser"

原文由 Arun CM 发布,翻译遵循 CC BY-SA 4.0 许可协议

对我有用的只是删除 iostreambits/stdc++.h 包括,保存文档并再次添加。这可以在不重新启动 VSCode 的情况下解决问题。

原文由 Mitko Nikov 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题