如何更新includePath。 #include检测到错误

时间:2018-12-30 19:03:00

标签: c compilation include-path

我试图在Windows笔记本电脑中使用vs代码进行编译,但它表示无法打开源文件“ unistd.h”“检测到#include错误。请更新您的includePath。(依此类推)”

我搜索了一个小时的解决方案,但仍然无法解决。

这是我尝试编译的代码。

#include <unistd.h>
#include <stdio.h>

int     main()
{
    int i, j, rows;

    printf("Enter number of rows: ");
    scanf("%d", &rows);

    for(i = 1; i <= rows; ++i)
    {
            for(j = 1; j <= i; ++j)
            {
                printf("* ");
            }
            printf("\n");
    }
    return(0);
}

然后 这是c_cpp_properties.jason文件

{
"configurations": [
    {
        "name": "Win32",
        "includePath": [
            "${workspaceFolder}/**"
        ],
        "defines": [
            "_DEBUG",
            "UNICODE",
            "_UNICODE"
        ],
        "windowsSdkVersion": "10.0.17763.0",
        "compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx64/x64/cl.exe",
        "cStandard": "c11",
        "cppStandard": "c++17",
        "intelliSenseMode": "msvc-x64"
    }
],
"version": 4

}

我应该在此jason文件中添加些什么以“升级includePath”?

1 个答案:

答案 0 :(得分:0)

您应该使用<angled> include来包含unistd.h(除非您在同一目录中拥有自己的unistd.h)

#include <unistd.h>
  

如果<>中包含头文件,则预处理器将搜索预定的目录路径以找到头文件。如果头文件包含在“”中,则预处理器将在与源文件相同的目录中查找头文件。