29

I am trying to setup visual studio code to program in c++. I have already installed the extensions C/C++ and 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 undefined and when I write it as std::cout the error I get then is namespace std has no member cout . Following is my task.json file:

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

2
  • 1
    Your code builds fine on VC++. Commented May 21, 2017 at 8:45
  • 1
    Is your source file a cpp file or a c file? Perhaps the compiler is confused about the language because of the file extension. Another possibility is that the installation is corrupted and there is no cout in iostream. Try reinstalling... Commented May 21, 2017 at 10:02

10 Answers 10

85

Its a bug.

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

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

4
  • 4
    Fyi: This bug and its solution still exist. My VSCode version is: Version: 1.45.0, Commit: d69a79b73808559a91206d73d7717ff5f798f23c. Thanks again for the solution! :) Commented May 13, 2020 at 14:33
  • 1
    Still exists: 1.55.2 3c4e3df9e89829dce27b7b5c24508306b151f30d x64
    – Sintrias
    Commented Apr 21, 2021 at 15:53
  • > namespace "std" has no member "unordered_set" C/C++(135) Still there and the workaround works! C/C++ extension: ms-vscode.cpptools v1.13.9 VS Code: Version: 1.74.3 (user setup) Commit: 97dec172d3256f8ca4bfb2143f3f76b503ca0534 Date: 2023-01-09T16:59:02.252Z
    – Liviu
    Commented Feb 2, 2023 at 11:13
  • Having a link to an actual bug (github issue) would be nice.
    – Liviu
    Commented Feb 2, 2023 at 13:46
4

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

{
"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://code.visualstudio.com/docs/languages/cpp

2

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

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

1
  • Not from some time: "closed this as completed on Aug 2, 2018".
    – Liviu
    Commented Feb 2, 2023 at 10:53
1

I too experienced the same issue after the VS Code Updated to v1.57.
After a long time spending on what's the issue, I have come to know that it is a bug due to this recent update. It has also updated the existing installed extensions which I had. C/C++ Microsoft Extension-(C/C++ IntelliSense, debugging, and code browsing.) is also one among them. It was also updated from 1.4.0 to 1.4.1.
So I finally sorted out that the actual bug was in this extension's v1.4.1 So I downgraded again to old version which was working fine for me.

Steps to Install Old version of same extension:

  1. Click the Extension
  2. Click down arrow near Uninstall
  3. Click Install Another Version...
  4. And now install the version which worked fine for you.
0
0

I had a problem with vscode to not detect #define constants from other files. Solved this for me by going to: file > preferences > Settings > Extentions > C/C++

Scroll down to C_Cpp › Default: Intelli Sense Mode and change the value from default to your compiler (gcc-x64 in my case).

0

I forgot to add #include iostream. After adding the problem was solved.

0

Alt + f4 and restarted vscode. The error was gone!

0

What works for me, is just deleting the iostream or bits/stdc++.h include, saving the document and adding it again. This fixes the issue without restarting VSCode.

0

I don't think you need to change the settings of the extension, as it is also specified that doing so gives "fuzzy" intellisense.

I was able to solve the problem by fixing the c_cpp_properties.json file:

"intelliSenseMode": "${default}"

which might have been changed as you switch devices. I worked on both Windows and Mac, so doing this will automatically identify the system you're working on.

0

In my case, it occurred because inconsistent compiler settings:

  1. I have both Visual Studio and TDM-GCC-64 installed in Windows
  2. I configured the vscode setting C_Cpp > Default: System Include Path to include directories of TDM-GCC-64
  3. I keep the vscode setting C_Cpp › Default: Compiler Path empty (at the same time vscode automatically detects my Visual Studio and uses it as Compiler Path)

solution: configure also C_Cpp › Default: Compiler Path to path/to/gcc.exe

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.