ceil 可以在不包含的情况下工作在视觉c++ 2010年

发布于 12-18 01:52 字数 284 浏览 4 评论 0原文

我刚刚在 Visual Studio 2010 中编写了一个简单的 C++ 程序,并使用了 ceil 函数。但我忘记包含 ,只包含 。令人惊讶的是我的代码编译成功并且运行没有任何错误。我读过一本 C++ 书籍,它清楚地表明要使用 ceil 函数,您必须包含 。为什么会出现这种情况?谁能给我解释一下吗?谢谢!

I just wrote a simple C++ program in Visual Studio 2010 and I use ceil function. But I forgot to include the <cmath> and only included the <iostream>. Surprisingly my code compiled successfully and ran without any error. I read a C++ book and it clearly says that to use ceil function you must include <cmath> or <math.h>. Why this happens? Can anyone explain me? Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

冷︶言冷语的世界2024-12-25 01:52:00

该标头是从其他(间接)包含的标头间接包含的。

要找出哪一个,请从项目选项中启用“保留预处理源”(/P) 并检查生成的 (*.i) 文件

更新 刚刚发现 VS2010已重命名相关选项:

在此处输入图像描述

The header is indirectly included from some other (indirectly) included header.

To find out which one, enable 'keep preprocessed source' (/P) from the project options and inspect the resulting (*.i) file

Update Just found out that VS2010 has renamed the related option:

enter image description here

兮子2024-12-25 01:52:00

从技术上讲,允许实现自动在系统标头中包含任何标头。但这是实现定义的。

在某些情况下, 已包含在内,在其他情况下则未包含 - 同样适用于所有其他标准标头。

这个问题出现在这个问题上:https:// stackoverflow.com/questions/7632926/is-this-ac-program-or-c-program-how-to-decide

除此之外,它可能会被其他包含间接包含。

Technically speaking, implementations are allowed to automatically include any header in the system headers. But this is implementation defined.

In some cases, <cmath> is already included, in other cases, it isn't - same applies to all the other standard headers.

This issue came up on this question: https://stackoverflow.com/questions/7632926/is-this-a-c-program-or-c-program-how-to-decide

That aside, it's possible that it could be indirectly included by other includes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文