When using include with quotes #include "filename.h"
the Preprocessor looks for the file first in the current directory and if it does not find it, it will look in the same places when using include with < >
Usually used to include files from the program itself.
When using #include <filename>
the Preprocessor will behave in a manner dependent on which implementation it is using, but will usually look in the normal (default) location of includes first, so it is usually used to include headers from the standard library.
That said, it is important to note for example that string. h and cstring are not the same thing
string. h is a C header (libc) and cstring is a C++ header (libstdc++)
Although it has the same functionality (this is mandatory), there are implementation differences mainly on the issue of namespaces, in which headers that start with C ex.: cstdio in C++ put the definitions in the Std namespace, while in stdio. h put in the global namespace, giving scope differences.
If you read the headers, you will see that in cstdio of libstdc++ you will find a #include "stdio. h" of the libc, and some implementation details
because in fact what this header does is a wrapper to use this C library according to the C standard++.
Most of the time it doesn’t change much, now there are cases for example as in Math. h vs cmath in which C++ library implementation changes a lot, especially overloads for different types and const specifiers.
https://stackoverflow.com/questions/8734230/math-interface-vs-cmath-in-c/8734292#8734292
So that,at least in my opinion, is more sensible when programming in C++ always use
#include <cmath>
and when programming in C
#include "math.h"
The difference between
<cmath>
and<math.h>
is thenamespace
. All functions of<math.h>
are declared in the global scope while in<cmath>
they are within the standard namespace:std
.– Lacobus