我正在尝试设置visual代码,以便在c++中编程。我已经安装了扩展C/C++和C/C++ Intellisense
以下是我的代码:
#include<iostream>
using namespace std;
int main()
{
cout<< "hello" ;
}
我得到的错误是identifier cout is undefined
,当我将它写成std::cout
时,我得到的错误是namespace std has no member cout
。以下是我的task.json
文件:
{
"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
}
}
}
]
}
我该怎么解决这个问题?
发布于 2018-04-04 06:13:07
这是一个bug。
有一个解决这个错误的方法,转到VS代码中的File -> Preferences -> Settings
并进行更改
"C_Cpp.intelliSenseEngine": "Default"
到"C_Cpp.intelliSenseEngine": "Tag Parser"
发布于 2018-04-20 06:54:38
我使用的是VSCode版本1.22.2和MinGW编译器,下面的配置适用于我:
{
"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
}
也参考这些链接:https://github.com/Microsoft/vscode-cpptools/blob/master/Documentation/LanguageServer/MinGW.md
发布于 2017-05-21 15:26:53
我也有同样的问题,发现这是一个vscode错误。请参阅下面的链接。
https://stackoverflow.com/questions/44094817
复制相似问题