Including C headers inside a C++ program

佐手、 提交于 2019-11-27 03:56:47

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"
}
Flash
#ifdef __cplusplus
extern "C"
{
#endif

// your functions here for the header

#ifdef __cplusplus
}
#endif

This format should help you use the header files for both C and C++ without any problem ...

Hope this helps...:)

I'm not sure what you need exactly, but if you want to use old fashioned C functions inside you C++ program, you can easy include them by removing the .h and add a "c" prefix.

for example if you want to include math.h use

#include <cmath>

Just include them inside a extern "C" block an they should work like expected.

You can #include them using their original names. #include <stdio.h> works just fine in C++.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!