Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 374
Arjun Vasudevan Avatar asked Jul 25 '10 12:07

Arjun Vasudevan


People also ask

Is it correct to include all header files in AC program?

By including a header file, we can use its contents in our program. C++ also offers its users a variety of functions, one of which is included in header files. In C++, all the header files may or may not end with the “. h” extension but in C, all the header files must necessarily end with the “.

What is the purpose of including header files in C program?

System header files declare the interfaces to parts of the operating system. You include them in your program to supply the definitions and declarations you need to invoke system calls and libraries. Your own header files contain declarations for interfaces between the source files of your program.

Can you include C headers in C++?

You can #include them using their original names. #include <stdio. h> works just fine in C++. The C standard headers are required to work in standard C++, although you may be putting more than you like into the global namespace.

What should be included in C header?

In C language, header files contain the set of predefined standard library functions. The “#include” preprocessing directive is used to include the header files with “. h” extension in the program.


Video Answer


1 Answers

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" } 
like image 70
Scharron Avatar answered Sep 21 '22 22:09

Scharron