Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include header files

Tags:

Does it matter how I import header files? I've seen double quotes as well as arrows used.

#include <stdlib.h> #include "Some_Header.h" 

Does it matter if they're capitalized a certain way as well? Experimenting around with this, it seems neither matters, but I figure there must be a reason for tutorials doing it the way they do.

Another question is, (coming from Java here), how do I access a class outside the file it was defined in? Say, I have one.cpp and two.cpp.

In one.cpp:

class Something {     ... 

In two.cpp:

class SomethingElse {     Something *example;     ... 

Like that? In Java you'd just preface a class name with "public." In C++, wrangling classes seems to be a bit more difficult..

like image 334
arjs Avatar asked Sep 18 '10 09:09

arjs


People also ask

How do I add a header file?

To make a header file, we have to create one file with a name, and extension should be (*. h). In that function there will be no main() function. In that file, we can put some variables, some functions etc.

Do you need to include in header files?

A TL;DR definition: A header file must include the header files that directly define each of the types directly used in or that directly declare each of the functions used in the header file in question, but must not include anything else.

Can you #include in a header file C?

C language has numerous libraries that include predefined functions to make programming easier. In C language, header files contain the set of predefined standard library functions. You request to use a header file in your program by including it with the C preprocessing directive “#include”.

How does including a header file work?

The #include directive tells the C preprocessor to include the contents of the file specified in the input stream to the compiler and then continue with the rest of the original file. Header files typically contain variable and function declarations along with macro definitions. But, they are not limited to only those.


1 Answers

Angle brackets in #include directives means the search path is limited to the "system" include directories. Double quotes mean the search path includes the current directory, followed by the system include directories.

The case of the filename matters when your OS is using a filesystem that is case sensitive. It sounds like you might be using Windows or Mac OS X, where filenames are case insensitive by default.

like image 105
Greg Hewgill Avatar answered Sep 21 '22 08:09

Greg Hewgill