Search code examples
c++cheaderheader-filesbgi

Including C headers inside a C++ program


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.


Solution

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