Including C headers inside a C++ program

Arjun Vasudevan picture Arjun Vasudevan · Jul 25, 2010 · Viewed 45.5k times · Source

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.

I could include the stdio.h library inside my cpp file as : #include <cstdio>. How do I include the other library files?

How do I add the graphics.h library?

I'm using Microsoft Visual Studio 6.0 Enterprise Edition and also Turbo C++ 3.0.

Answer

Scharron picture Scharron · Jul 25, 2010

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"
}