首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >为什么visual代码告诉我cout不是std名称空间的成员?

为什么visual代码告诉我cout不是std名称空间的成员?
EN

Stack Overflow用户
提问于 2017-05-21 08:35:35
回答 7查看 47.3K关注 0票数 24

我正在尝试设置visual代码,以便在c++中编程。我已经安装了扩展C/C++C/C++ Intellisense

以下是我的代码:

代码语言:javascript
运行
复制
#include<iostream>
using namespace std;

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

我得到的错误是identifier cout is undefined,当我将它写成std::cout时,我得到的错误是namespace std has no member cout。以下是我的task.json文件:

代码语言:javascript
运行
复制
{
"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
            }
        }
    }
]
}

我该怎么解决这个问题?

EN

回答 7

Stack Overflow用户

回答已采纳

发布于 2018-04-04 06:13:07

这是一个bug

有一个解决这个错误的方法,转到VS代码中的File -> Preferences -> Settings并进行更改

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

票数 70
EN

Stack Overflow用户

发布于 2018-04-20 06:54:38

我使用的是VSCode版本1.22.2和MinGW编译器,下面的配置适用于我:

代码语言:javascript
运行
复制
{
"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
}

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

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

票数 4
EN

Stack Overflow用户

发布于 2017-05-21 15:26:53

我也有同样的问题,发现这是一个vscode错误。请参阅下面的链接。

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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44094817

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档