在 C 程序中包含 C 头文件

新手上路,请多包涵

我有一个 C++ 程序 (.cpp),我希望在其中使用 C 头文件中存在的一些函数,例如 stdio.h、conio.h、stdlib.h、graphics.h、devices.h 等。

我可以在我的 cpp 文件中包含 stdio.h 库: #include <cstdio> 。如何包含其他库文件?

如何添加 graphics.h 库?

我正在使用 Microsoft Visual Studio 6.0 企业版和 Turbo C++ 3.0。

原文由 Arjun Vasudevan 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 440
2 个回答

对于 C 标准 C 头文件(stdio、stdlib、assert、…)的列表,请在 ac 前面添加并删除 .h。例如 stdio.h 变成 cstdio。

对于其他标题,请使用

extern "C"
{
  #include "other_header.h"
}

原文由 Scharron 发布,翻译遵循 CC BY-SA 2.5 许可协议

如果你把它放在你的标题中:

 #ifdef __cplusplus
extern "C"
{
#endif

// your normal definitions here

#ifdef __cplusplus
}
#endif

然后它将适用于 C 和 C++ 没有任何问题…

希望这可以帮助…:)

原文由 Flash 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题