首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >名称空间"std“没有成员"cout”("cin“、"endl”、.是一样的)

名称空间"std“没有成员"cout”("cin“、"endl”、.是一样的)
EN

Stack Overflow用户
提问于 2022-10-12 09:06:54
回答 2查看 308关注 0票数 1

最近,经过很长一段时间,我在大学里重新安装了C++。在安装了C++扩展包之后,我用"HelloWorld“代码进行了测试,发现名称空间"std”的所有成员都犯了错误,如下所示。我仍然可以像往常一样编译和运行它,但是显示的错误让我非常不高兴。

我试着找出一些解决办法。所有这些问题都与缺少的#include<iostream>using namespace std、更改intelliSenseModeC_Cpp.errorSquiggles或其他相关,但没有一个是正确的答案。

为什么会发生这种事?

这是我的c_cpp_properties.json:

代码语言:javascript
复制
{
"configurations": [
    {
        "name": "Win32",
        "includePath": [
            "D:/Code/Path/mingw64/x86_64-w64-mingw32/include",
            "D:/Code/Path/mingw64/lib/gcc/x86_64-w64-mingw32/12.2.0/include",
            "D:/Code/Path/mingw64/include/c++/12.2.0/x86_64-w64-mingw32"
        ],
        "defines": [
            "_DEBUG",
            "UNICODE",
            "_UNICODE"
        ],
        "compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe",
        "cStandard": "c17",
        "cppStandard": "c++17",
        "intelliSenseMode": "windows-msvc-x64"            
    }
],
"version": 4

}

settings.json:

代码语言:javascript
复制
{
"cSpell.words": [
    "heapify",
    "HUST",
    "Inorder"
],
"C_Cpp.errorSquiggles": "EnabledIfIncludesResolve"

}

你好-world.cpp:

代码语言:javascript
复制
#include <iostream>

int main()
{
  std::cout << "Hello world" << std::endl;
}
EN

回答 2

Stack Overflow用户

发布于 2022-10-12 09:29:06

Why is visual studio code telling me that cout is not a member of std namespace?答案来看,它应该是VS代码中的一个bug。

您应该进入VS代码中的File -> Preferences -> Settings并进行更改

"C_Cpp.intelliSenseEngine": "Default""C_Cpp.intelliSenseEngine": "Tag Parser"。也许这个答案有帮助!

票数 1
EN

Stack Overflow用户

发布于 2022-10-12 09:56:27

因此,在@AlanBirtles@n.1.8e9-where's-my-sharem评论之后,我尝试将compilerPath更改为../mingw64/bin/c++.exe,并且它确实有效。也许提供的C/C++扩展的默认路径在某些方面是错误的。非常感谢大家

代码语言:javascript
复制
{
"configurations": [
    {
        "name": "Win32",
        "includePath": [
            "D:/Code/Path/mingw64/x86_64-w64-mingw32/include",
            "D:/Code/Path/mingw64/lib/gcc/x86_64-w64-mingw32/12.2.0/include",
            "D:/Code/Path/mingw64/include/c++/12.2.0/x86_64-w64-mingw32"
        ],
        "defines": [
            "_DEBUG",
            "UNICODE",
            "_UNICODE"
        ],
        // "compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe",
        "compilerPath": "D:/Code/Path/mingw64/bin/c++.exe",
        "cStandard": "c17",
        "cppStandard": "c++17",
        // "intelliSenseMode": "windows-msvc-x64"
        "intelliSenseMode": "windows-gcc-x86"
    }
],
"version": 4

}

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

https://stackoverflow.com/questions/74039252

复制
相关文章

相似问题

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