-1

I am on Linux. I have installed ms-vscode.cpptools for Visual Studio Code and my c_cpp_properties.json file looks like this:

{
    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "${workspaceRoot}",
                "/usr/include",
                "/usr/local/include"
            ],
            "defines": [],
            "browse": {
                "path": [
                    "/usr/include",
                    "/usr/local/include"
                ],
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": ""
            }
        },
        {
            "name": "Linux",
            "includePath": [
                "${workspaceRoot}",
                "/usr/include/c++/5.4.0",
                "/usr/local/include",
                "/usr/lib/clang/3.8.0/include",
                "/usr/include"
            ],
            "defines": [],
            "browse": {
                "path": [
                    "/usr/include/c++/5.4.0",
                    "/usr/local/include",
                    "/usr/lib/clang/3.8.0/include",
                    "/usr/include"
                ],
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": ""
            }
        },
        {
            "name": "Win32",
            "includePath": [
                "${workspaceRoot}",
                "C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/include"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE"
            ],
            "browse": {
                "path": [
                    "C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/include/*"
                ],
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": ""
            }
        }
    ]
}

I have made a task.json file like this:

{
    "version": "0.1.0",
    "command": "g++",
    "isShellCommand": true,
    "args": ["-g", "-std=c++11", "-Wall", "-Wextra", "-O2", "${file}"],
    "showOutput": "always"
}

I am trying to compile the following code:

#include <bits/stdc++.h>

using namespace std;

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

But I get the errors

  • cannot open source file "bits/stdc++.h"
  • identifier "cout" is undefined

However, if I use iostream instead of bits/stdc++.h, it finds the header file but still complains about cout being undefined. I can compile without any problems from terminal.

What am I doing wrong here?

Edit: As suggested in the comments, I have removed bits/stdc++.hand using namespace std;. My code looks like this now:

#include <iostream>

int main() {
    std::cout << "hello";
    return 0;
}

I now get the error:

  • namespace "std" has no member "cout"
Ata-E-Rabbi
  • 45
  • 1
  • 5

1 Answers1

1

Try to compile and run your code outside of visual studio code using g++.

I now get the error:

namespace "std" has no member "cout"

Where you get this error, from compiler or in editor with highlight?

Community
  • 1
  • 1
AntGeorge
  • 63
  • 1
  • 1
  • 9
  • All problems occur when I try to compile from Visual Studio Code. I have mentioned in my question that I can compile from terminal without any problems. – Ata-E-Rabbi May 22 '17 at 00:13
  • 1
    I tried to build the file in visual studio code with your settings (task.json, c_cpp_properties.json) and was successfully finished. I noticed in editor there is a red underlined in the cout as if there was a mistake, i dont know why. But you can remove this underline if you add this **"C_Cpp.errorSquiggles": "Disabled"** in your settings.json file – AntGeorge May 22 '17 at 15:20
  • Yeah, I removed the MS C/C++ tools and started using C/C++ Clang Command Adapter and it's been great aside from a lack of code navigation. Guest that's the best that can be done with VSCode for C/C++ at the moment. – Ata-E-Rabbi May 23 '17 at 15:14