Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ Header style

What's the preferred policy of header files in C++ projects: <test.h> or "test.h"? In my experience I use:

  1. #include <test_lib.h> to include C/C++ headers, third-part libraries (boost and etc.) which path specified in project settings.
  2. #include "my_test.h" - it's used for headers files existing in project.

Any other practices can be applied here?

Is it ok to include header files with relative paths: like #include "../new_test.h"? Or is it better to move relative paths to project settings?

like image 939
Denis Solovov Avatar asked Jul 14 '26 01:07

Denis Solovov


1 Answers

Angle brackets are use to include system headers. Theoretically, IIRC, they're not even necessarily files. In practice, <> means do not search current directory, only the include path, whereas "" means look in current directory and then search the include path.

As for relative paths, it probably depends on your environment, I'd suggest path relative to your project include path (as specified by -I).

like image 173
Michael Krelin - hacker Avatar answered Jul 15 '26 17:07

Michael Krelin - hacker