我正试着读一个键击,然后停止一个密码。在C.
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
bool starting()
{
char c;
if (kbhit())
{
c=getch();
if (c=="S"||c=="s")
{
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
int main()
{
while(!starting)
{
printf("line 1");
delay(100);
}
return 0;
}如果没有stdbool.h,它会显示错误,比如
syntax error: identifier 'starting',
syntax error: ";"
syntax error: ")"
'starting': undeclared identifier对于stdbool.h,它表示文件未找到。我的编译器是Visual 2010附带的编译器。
有什么建议怎么去掉这个吗?如何仍然使用返回布尔值的函数?
添加了对不起!简短的评论补充道。基本上解决了。谢谢大家
添加了更多的错误:编译后:它读取:
filename.obj unresolved external symbol _delay referenced in function _main.我该怎么办?
发布于 2013-06-22 10:02:18
stdbool.h是在C99中引入的,Visual不支持C99。您可以自己定义类型。一种可能的办法是:
typedef int bool;
#define true 1
#define false 0发布于 2013-06-22 09:57:40
同时存在三个问题:
bool是它自己的一种类型,但是您可以定义它(例如,通过stdbool.h或者仅仅通过对任何其他整体类型使用typedef (通常是unsigned char或int;这可能是内存使用还是基于性能的问题)。std**.h头,特别是旧版本而闻名。所以您很可能在VS 2010中没有stdbool.h (文件没有找到错误的原因)。while(!starting)中缺少括号。https://stackoverflow.com/questions/17249388
复制相似问题