Including C headers inside a C++ program(在 C++ 程序中包含 C 头文件)
问题描述
我有一个 C++ 程序 (.cpp),我希望在其中使用 C 头文件中的一些函数,例如 stdio.h、conio.h、stdlib.h、graphics.h、设备.h等
I have a C++ program (.cpp) inside which I wish to use some of the functions which are present inside the C header files such as stdio.h, conio.h, stdlib.h, graphics.h, devices.h etc.
我可以在我的 cpp 文件中包含 stdio.h 库:#include <cstdio>
.如何包含其他库文件?
I could include the stdio.h library inside my cpp file as : #include <cstdio>
.
How do I include the other library files?
如何添加 graphics.h 库?
How do I add the graphics.h library?
我使用的是 Microsoft Visual Studio 6.0 企业版和 Turbo C++ 3.0.
I'm using Microsoft Visual Studio 6.0 Enterprise Edition and also Turbo C++ 3.0.
推荐答案
对于 C 标准 C 头文件(stdio、stdlib、assert、...)的列表,在前面加上 c 并删除 .h.例如 stdio.h 变成 cstdio.
For a list of C standard C headers (stdio, stdlib, assert, ...), prepend a c and remove the .h. For example stdio.h becomes cstdio.
对于其他标题,请使用
For other headers, use
extern "C"
{
#include "other_header.h"
}
这篇关于在 C++ 程序中包含 C 头文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 C++ 程序中包含 C 头文件


基础教程推荐
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 初始化列表*参数*评估顺序 2021-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- CString 到 char* 2021-01-01