Home > Mobile >  namespace "std" has no member "cout" ("cin", "endl",... are
namespace "std" has no member "cout" ("cin", "endl",... are

Time:10-13

Recently I re-installed C for my course at university after a long time. After installing the C Extension pack, I tested with "HelloWorld" code and found that all the members from namespace "std" make errors like in the following images. I can still compile and run it as usual, but the errors shown make me so displeased.

I tried to find some solutions. All of them related to missing #include<iostream>, using namespace std, changing the intelliSenseMode, C_Cpp.errorSquiggles, or something else, but none of them was the correct answer.

Why might this be happening?

Here are my c_cpp_properties.json:

{
"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:

{
"cSpell.words": [
    "heapify",
    "HUST",
    "Inorder"
],
"C_Cpp.errorSquiggles": "EnabledIfIncludesResolve"

}

hello-world.cpp:

#include <iostream>

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

CodePudding user response:

From Why is visual studio code telling me that cout is not a member of std namespace? answer, it should be a bug in VS code.

You should go to File -> Preferences -> Settings in VS Code and change

"C_Cpp.intelliSenseEngine": "Default" to "C_Cpp.intelliSenseEngine": "Tag Parser". Maybe this answer helps!

CodePudding user response:

So after @AlanBirtles and @n.1.8e9-where's-my-sharem comments, i tried to change the compilerPath to ../mingw64/bin/c .exe and its really worked. Maybe the default path of C/C extension provided is wrong in some ways. Thank you so much everyone

{
"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

}

  • Related