C/C++ error:unknown type name ‘bool’

ChatGPT 3.5 国内中文镜像站免费使用啦

零基础 C/C++ 学习路线推荐 : C/C++ 学习目录 >> C 语言基础入门

零基础 C/C++ 学习路线推荐 : C/C++ 学习目录 >> C 语言 pthread

零基础 C/C++ 学习路线推荐 : C/C++ 学习目录 >> C++ 面向对象

零基础 C/C++ 学习路线推荐 : C/C++ 学习目录 >> C++ 设计模式

零基础 C/C++ 学习路线推荐 : C/C++ 学习目录 >> C++ STL

零基础 C/C++ 学习路线推荐 : C/C++ 学习目录 >> C/C++ 技术杂谈

零基础 C/C++ 学习路线推荐 : C/C++ 学习目录 >> C/C++ 常用函数


一.error:unknown type name ‘bool’

报错的意思:未知的类型名:‘bool’

main.c: In function ‘main’:
main.c:6:4: error: unknown type name ‘bool’
    6 |    bool x = 1;
      |    ^~~~
main.c:11:4: error: unknown type name ‘bool’
   11 |    bool y = *(bool*)p;
      |    ^~~~
main.c:11:15: error: ‘bool’ undeclared (first use in this function)
   11 |    bool y = *(bool*)p;
      |               ^~~~
main.c:11:15: note: each undeclared identifier is reported only once for each function it appears in
main.c:11:20: error: expected expression before ‘)’ token
   11 |    bool y = *(bool*)p;
      |                    ^

C 语言标准 (C89) 没有定义布尔类型,所以会报错。而 C99 提供了一个头文件<stdbool.h> 定义了 bool , true 代表 1 ,false 代表 0 。只要导入 stdbool.h ,就能非常方便的操作布尔类型了。

/******************************************************************************************/
//@Author:猿说编程
//@Blog(个人博客地址): www.codersrc.com
//@File:C/C++ error:unknown type name 'bool'
//@Time:2022/02/16 07:00
//@Motto:不积跬步无以至千里,不积小流无以成江海,程序人生的精彩需要坚持不懈地积累!
/******************************************************************************************/


#include <stdbool.h>


二.猜你喜欢

  1. C语言 数组下标越界和内存溢出区别
  2. C语言 使用指针遍历数组
  3. C语言 指针和数组区别
  4. C语言 指针数组和数组指针区别
  5. C语言 野指针
  6. C语言 函数值传递和址传递
  7. 函数不定长参数
  8. C语言 函数指针
  9. C语言 指针函数
  10. C语言 回调函数 callback
  11. C语言 #pragma once
  12. C语言 #include <> 与 #include “” 区别
  13. C语言 const 修饰函数参数
  14. C语言 const 和 define 区别
  15. C语言 va_start / va_end / va_arg 自定义 printf 函数
  16. C语言 main 函数参数 main(int argc, char *argv[])
  17. C语言 结构体struct简介(一)
  18. C语言 结构体struct定义和使用(二)
  19. C语言 结构体struct数组(三)
  20. C语言 结构体struct指针(四)
  21. C语言 结构体struct成员函数(五)
  22. C语言 结构体struct嵌套(六)
  23. C语言 结构体struct值传递和址传递(七)
  24. C/C++ error: cannot assign to non-static data member within const member function ‘xxxx’
  25. C++ 关于类中 const 的使用
  26. C/C++ 条件编译 #ifdef
  27. C/C++ error C2065: “M_PI”: 未声明的标识符
  28. C/C++ error C2027: 使用了未定义类型“std::tuple”
  29. C/C++ vs 没有匹配 if 的非法 else 问题解决办法
  30. C/C++ Visual studio 中文注释导致编译不能通过
  31. C/C++ error C2589: “(”: “::”右边的非法标记
  32. C/C++ error:表达式是必须修改的左值
  33. C/C++ error C4996: ‘getch’: The POSIX name for this item is deprecated. Instead, use the ISO C++ conf
  34. C/C++ error C4146: 一元负运算符应用于无符号类型,结果仍为无符号类型
  35. C/C++ std::string 字符串分割
  36. Visual Studio 中 dumpbin 工具使用
  37. C/C++ error LNK2005:”XXX已经在 XXX.obj 中定义
  38. C/C++ 判断字符串是否为 utf-8 编码
  39. C/C++ uafxcwd.lib(afxmem.obj) : error LNK2005: “void * __cdecl operator new(unsigned int)” (??2@YAPAXI@Z) 已经在 LIBCMTD.lib(new.obj) 中定义解决办法
  40. C/C++ nafxcw.lib(appui1.obj) : error LNK2005: “class CWinApp * __cdecl AfxGetApp(void)” (?AfxGetApp@@YAPEAVCWinApp@@XZ) 已经在 uafxcwd.lib(afxinl2.obj) 中定义
  41. C/C++ void* 和 float 转换
  42. C/C++ void* 和 int 转换
  43. C/C++ void* 和 bool 转换
  44. C/C++ error:unknown type name ‘bool’

ChatGPT 3.5 国内中文镜像站免费使用啦
© 版权声明
THE END
喜欢就支持一下吧
点赞1 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容