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++.h
and 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"