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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44094817/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 15:35:55  来源:igfitidea点击:

Why is visual studio code telling me that cout is not a member of std namespace?

c++c++11visual-studio-code

提问by Nirvan Anjirbag

I am trying to setup visual studio code to program in c++. I have already installed the extensions C/C++and C/C++ Intellisense

我正在尝试设置 Visual Studio 代码以使用 C++ 进行编程。我已经安装了扩展C/C++C/C++ Intellisense

Following is my code:

以下是我的代码:

#include<iostream>
using namespace std;

int main()
{
 cout<< "hello" ;
}

The error I'm getting is identifier cout is undefinedand when I write it as std::coutthe error I get then is namespace std has no member cout. Following is my task.jsonfile:

我得到的错误是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
            }
        }
    }
]
}

How do i fix this?

我该如何解决?

回答by Arun CM

Its a bug!!!!.

There is a workaround for this bug, go to File -> Preferences -> Settingsin VS Code and change

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

它的一个错误!!!!

此错误有一个解决方法,转到文件 -> 首选项 ->VS Code 中的设置并更改

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

回答by Sangwoo Lee

I have a same problem and found that it is a vscode bug. Please refer to the link below.

我有同样的问题,发现它是一个 vscode 错误。请参考以下链接。

https://github.com/Microsoft/vscode-cpptools/issues/743

https://github.com/Microsoft/vscode-cpptools/issues/743

回答by Kiran

I am using VSCode version 1.22.2 with MinGW compiler and below config works for me:

我正在使用 VSCode 版本 1.22.2 和 MinGW 编译器,以下配置对我有用:

{
"configurations": [
    {
        "name": "MinGW",
        "intelliSenseMode": "clang-x64",
        "compilerPath": "C:/MinGW/bin/g++.exe",
        "includePath": [
            "${workspaceRoot}",
        ],
        "defines": [
            "_DEBUG"
        ],
        "browse": {
            "path": [
                "C:/MinGW/lib/gcc/mingw32/6.3.0/include",
                "C:/MinGW/lib/gcc/mingw32/6.3.0/include-fixed",
                "C:/MinGW/include/*"
                "${workspaceRoot}",
            ],
            "limitSymbolsToIncludedHeaders": true,
            "databaseFilename": ""
        }
    }
],
"version": 3
}

Refer these link too: https://github.com/Microsoft/vscode-cpptools/blob/master/Documentation/LanguageServer/MinGW.md

也参考这些链接:https: //github.com/Microsoft/vscode-cpptools/blob/master/Documentation/LanguageServer/MinGW.md

https://code.visualstudio.com/docs/languages/cpp

https://code.visualstudio.com/docs/languages/cpp