【问题标题】:#include errors detected. Please update your includePath. Squiggles are disabled for this translation unit in vscode when trying to code with C#include 检测到错误。请更新您的 includePath。尝试使用 C 编码时,vscode 中此翻译单元的曲线被禁用
【发布时间】:2021-04-17 11:49:24
【问题描述】:
[#include errors detected. Please update your includePath. Squiggles are disabled for this translation unit][1] (C:\Users\kw27w\OneDrive\Desktop\test\test.c).C/C++(1696)
cannot open source file "stdbool.h"C/C++(1696)

这就是发生的错误, 下有一条红线,当我点击它时会显示一个灯泡,它显示edit "includepath" settings,当我点击它时,它会移至“c_cpp_properties.json”。

如何以及在哪里可以在下面的配置中添加包含路径?

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "C:\\Users\\kw27w\\.vscode\\extensions\\ms-vscode.cpptools-1.3.0"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "cStandard": "c17",
            "cppStandard": "c++20",
            "intelliSenseMode": "windows-msvc-x64"
        }
    ],
    "version": 4
}

我的代码是

#include <stdbool.h>
#include <math.h>

/*
A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. The first few prime numbers are {2, 3, 5, 7, 11, ….}

The idea to solve this problem is to iterate through all the numbers starting from 2 to sqrt(N) using a for loop and for every number check if it divides N. If we find any number that divides, we return false. If we did not find any number between 2 and sqrt(N) which divides N then it means that N is prime and we will return True. 
Why did we choose sqrt(N)? 
The reason is that the smallest and greater than one factor of a number cannot be more than the sqrt of N. And we stop as soon as we find a factor. For example, if N is 49, the smallest factor is 7. For 15, smallest factor is 3.
*/

bool is_prime(int n){
  int i, flag = 1;
    // Iterate from 2 to sqrt(n)
    for (i = 2; i <= sqrt(n); i++) {
 
        // If n is divisible by any number between
        // 2 and n/2, it is not prime
        if (n % i == 0) {
            flag = 0;
            break;
        }
    }
 
    if (n <= 1)
        flag = 0;
 
    if (flag == 1) {
        return true;
    }
    else {
        return false;
    }
}

【问题讨论】:

  • c++代码不需要包含stdbool.h
  • 实际上是 c 代码而不是 c++
  • 那么不要用c++标记它

标签: c visual-studio-code


【解决方案1】:

我假设您使用的是 Mac?我刚刚遇到了同样的问题。

你有安装自制软件吗?如果没有,那是你的问题。 Mac OS 缺少 Windows 操作系统通常具有的很多东西 [根据 HomeBrew 主页,“Homebrew,macOS(或 Linux)缺少的包管理器”]。 因此,我们需要将缺少的所有内容下载到我们的 Mac OS 上,而 HomeBrew 就是解决方案:https://brew.sh

如果由于某种原因您无法安装 HomeBrew,那么微软在这里有一个解决方案: https://vcpkg.io/en/getting-started.html

让我知道结果如何。

【讨论】:

    猜你喜欢
    • 2018-12-16
    • 2021-09-20
    • 2020-10-10
    • 1970-01-01
    • 2018-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多