【发布时间】: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