Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 447
Nirvan Anjirbag Avatar asked May 21 '17 08:05

Nirvan Anjirbag


People also ask

Is cout a member of STD?

c++ - cout is not a member of std - Stack Overflow. Stack Overflow for Teams – Start collaborating and sharing organizational knowledge.

Why can't I run code in VS Code?

You simply need to change the line "externalConsole" and set it to "true". And that's basically it. After that you simply Run your program with (F5). Keep in mind that if you change something in your original code you need to run it with "Run Code", (ctrl+alt+n) so that the uptades you do get saved and "compiled".


2 Answers

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"

like image 50
Arun CM Avatar answered Sep 30 '22 05:09

Arun CM


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

like image 44
Kiran Avatar answered Sep 30 '22 06:09

Kiran