我在Windows上使用Visual Studio代码。我已经在我的电脑上安装了64位Mingw。
我已经按照简单程序对vs代码进行了测试
#include <stdio.h>
int main() {
int a,b,c;
printf("enter the no.");
scanf("%d%d",&a,&b);
c=a+b;
printf("%d",c);
return 0;
}
和相应的json文件是:
{
"configurations": [{
"name": "Win64",
"intelliSenseMode": "msvc-x64",
"includePath": [
"C:/MinGW/include/c++/3.4.5",
"${workspaceRoot}"
],
"defines": [
"_DEBUG",
"UNICODE"
],
"compileCommands": "",
"browse": {
"path": [
"C:/MinGW/include/c++/3.4.5",
"${workspaceRoot}"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
}],
"version": 3
}
现在,当我将光标移到#include时,它仍然显示以下错误:
#include errors detected. Please update your includePath. IntelliSense features
for this translation unit (C:\Users\h\Documents\vsc\prg1.cpp) will be provided
by the Tag Parser.
cannot open source file "stdio.h"
在Visual Studio代码的问题部分,显示了8个问题: -
我不知道该怎么做?请帮忙 - 谢谢
我假设您提供的JSON文件是您的Visual Studio项目配置。
在该文件中,"includePath"
字段是告诉Visual Studio在哪里查找标题的字段。此字段设置为两个位置:
C:/MinGW/include/c++/3.4.5
,包含标准C ++标头。<stdio.h>
是标准的C头,因此Visual Studio无法在C ++头文件中找到它。要快速修复,您可以尝试包含<cstdio>
。
如果您想以干净的方式执行操作,则需要更改项目配置以查找标准C头:
Properties
C++ > General
部分下,找到Additional include directories
字段C:/MinGW/include/
,但您可能需要自己检查,因为它取决于您的MinGW安装。此方法仅影响当前项目,因此您可能需要再次为其他项目执行此操作。如果您想使其永久化以便未来的解决方案也受到影响,请打开Tools
菜单并转到Options
。在侧边栏上,找到Projects and solutions
并前往VC++ directories
。然后,您可以将目录路径附加到此处的包含路径字段。但是,在VS2013及更高版本中禁用了此功能。
附加说明:Visual Studio可以执行C,但它不是为其量身定制的。虽然C编译器将用于任何具有.c
扩展名的文件,但Visual Studio中没有为C程序设计的解决方案或项目类型。