试图用'#包括LT&;&stdbool.h GT;'在VS 2010中 [英] trying to use '#include <stdbool.h>' in VS 2010

查看:346
本文介绍了试图用'#包括LT&;&stdbool.h GT;'在VS 2010中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用stdbool.h库文件在C程序。当我尝试编译,但是,会出现一条错误消息,智能感知无法打开源文件stdbool.h。

任何人都可以请告知我怎么会得到Visual Studio的认识到这一点?这是头文件,甚至是否有效?我读一本书,学习C语言编程。


解决方案

 的typedef INT BOOL;
#定义假0
真正的#define 1

工作得很好。在Windows头做同样的事情。但绝对没有理由担心有关浪费了内存存储在双位值消耗的 INT

作为亚历山大的评论中提到,微软的C编译器(捆绑使用Visual Studio)<一个href=\"http://connect.microsoft.com/VisualStudio/feedback/details/99132/c99-header-stdbool-h-missing\">doesn't支持C99 并有可能不会。这是不幸的,因为 stdbool.h 和其他许多更为实用的功能在C99支持,但不是在Visual Studio。它停留在过去,只支持被称为C89的旧标准。我很惊讶你还没有碰到试图确定什么地方比一个块的开头其他变量的一个问题。那咬我的每个的时候,我写VS C $ C $角

一个可能的解决办法是配置的Visual Studio编译code和C ++。随后的几乎的您在C99书中读到的一切都无需编译器窒息。在C ++中,键入布尔是内置的。为了让这种变化,你可以在IDE中编辑项目的编译设置,也可以简单地重命名文件有一个 CPP 扩展(而不是 C )。 VS会自动设置相应的编译模式。

不过说实话,如果你想学习C(并因此时下C99)更好的解决方法就是拿起不同的编译器。 MinGW的是一个不错的选择,如果你在Windows上运行。人都喜欢的 code很多:: Blocks的IDE

I'm trying to use the stdbool.h library file in a C program. When I try to compile, however, an error message appears saying intellisense cannot open source file stdbool.h.

Can anyone please advise how I would get visual studio to recognise this? Is this header file even valid? I'm reading a book on learning C programming.

解决方案

typedef int bool;
#define false 0
#define true 1

works just fine. The Windows headers do the same thing. There's absolutely no reason to fret about the "wasted" memory expended by storing a two-bit value in an int.

As Alexandre mentioned in a comment, Microsoft's C compiler (bundled with Visual Studio) doesn't support C99 and likely isn't going to. It's unfortunate, because stdbool.h and many other far more useful features are supported in C99, but not in Visual Studio. It's stuck in the past, supporting only the older standard known as C89. I'm surprised you haven't run into a problem trying to define variables somewhere other than the beginning of a block. That bites me every time I write C code in VS.

One possible workaround is to configure Visual Studio to compile the code as C++. Then almost everything you read in the C99 book will work without the compiler choking. In C++, the type bool is built in. To make this change, you can edit your project's compilation settings within the IDE, or you can simply rename the file to have a cpp extension (rather than c). VS will automatically set the compilation mode accordingly.

But honestly, the better solution if you're trying to learn C (and therefore C99 nowadays) is to just pick up a different compiler. MinGW is a good option if you're running on Windows. Lots of people like the Code::Blocks IDE

这篇关于试图用'#包括LT&;&stdbool.h GT;'在VS 2010中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆