今天在Dev-C下用到“while(true)”结构是遇到了一个问题,代码如下:
#include <stdio.h>
int main(int argc, char *argv[]) {
while(true){
break;
}
return 0;
}
报错:[Error] 'true' undeclared (first use in this function)
原来我一直以为“true”是C语言中的关键字.....现在发现自己太浅薄了!!!!
我查了一下库,找到了头文件 "stdbool.h" ,在里面找到了:
/*
* ISO C Standard: 7.16 Boolean type and values <stdbool.h>
*/
#ifndef _STDBOOL_H
#define _STDBOOL_H
#ifndef __cplusplus
#define bool _Bool
#define true 1
#define false 0
true 和 false 就是预处理宏,而非关键字
包含<stdbooll.h>就ok了