Site icon Learn C++

What is The Difference Between #include And #include “…”?

What is the difference between #include <…> and #include “…”? What does #include “filename” mean for a C++ compiler? What does <filename> means for a C++ IDE? How can I use include? How can I add header paths into #include <> usage? Let’s answer these questions!

What does #include “filename” mean?

In general, in C++ if a filename is declared between ” ” it means it is pointing to an exact file location. In other words, the #include “filename” line means the #include preprocessor searches for that exact full path or file in that directory path as the file containing the directive. If the programmer has some specific headers this method is used to include these headers containing other definitions, included headers, classes, methods, and variables.

For example, for 32bits applications, an iostream can be included as below,

[crayon-67403f53d014b320127547/]

and for a 64bits application you need 64bit version of iostream, it can be included as below,

[crayon-67403f53d0156575656680/]

What does #include <filename> mean?

If #include preprocessor uses filename between ‘<‘ and ‘>’ that generally points a file which can be found in the default paths of that C++ compiler or C++ IDE. This is used to include standard library header files. In other words, the #include <filename> line means the #include preprocessor searches in an implementation-dependent manner, normally in search directories pre-designated by the compiler/IDE.

[crayon-67403f53d0159237640824/]

This makes for a more friendly usage than the two preceding examples. The compiler includes appropriate header folders depending on the platform and whether it is a 32bit or 64bit version.

What is the difference between #include <…> and #include “…”?

The two sections above are probably enough to explain the main difference, as you can see the difference is in the location where the preprocessor searches for the included file.

How can I add header paths into #include <…> usage?

Assuming you would like to use the #include <filename> method, but you don’t know how to add some new headers in your specific folders to your C++ projects? In C++ Builder there is a “C++ Compiler Directories and Conditionals” option. You can add your specific directory paths for the specific platform settings. To do this, do the following;

1. Go to Project -> Options … menu in RAD Studio or C++ Builder. There is a Directories and Conditionals section in the Building->C++ Compiler section.

2. On the right side, there is a “…” ellipse button at the end of the Include file search path section,

3. if you select this there will be an Include file search path window, you can add your folders by using the yellow folder icon (or you can directly type it in), then press “Add” button.

4. Then press OK and Save ..

These options will be recorded in the project file and saved along with it.

A more complete description can be found in the Embarcadero’s Doc Wiki here, and in the GCC documentation on search paths here.

C++ Builder is the easiest and fastest C and C++ IDE for building simple or professional applications on the Windows, MacOS, iOS & Android operating systems. It is also easy for beginners to learn with its wide range of samples, tutorials, help files, and LSP support for code. RAD Studio’s C++ Builder version comes with the award-winning VCL framework for high-performance native Windows apps and the powerful FireMonkey (FMX) framework for cross-platform UIs.

There is a free C++ Builder Community Edition for students, beginners, and startups; it can be downloaded from here. For professional developers, there are Professional, Architect, or Enterprise versions of C++ Builder and there is a trial version you can download from here.

Exit mobile version