在C ++程序中包含C头

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

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

如何添加graphics.h库?

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

有关C标准C标头(stdio,stdlib,assert,…)的列表,请在ac之前添加并删除.h。 例如,stdio.h成为cstdio。

对于其他标题,请使用

 extern "C" { #include "other_header.h" } 
 #ifdef __cplusplus extern "C" { #endif // your functions here for the header #ifdef __cplusplus } #endif 

这种格式应该可以帮助您使用C和C ++的头文件而不会有任何问题……

希望这可以帮助…:)

我不确定你需要什么,但如果你想在C ++程序中使用老式的C函数,你可以通过删除.h并添加一个“c”前缀来轻松包含它们。

例如,如果要包含math.h使用

 #include  

只需将它们包含在extern "C"块中,它们应该像预期的那样工作。

您可以使用原始名称#include它们。 #include 在C ++中运行得很好。