the sequence of including headfiles

Oct 26, 2021 at 12:17pm
the sequence of including headfiles may affect the success of compilation.
and now i am wondering if it is important to include headfiles in a particular sequence if all the headfiles included in my program are the headfiles all included in GNU C/C++ Library.
just like:
1
2
#include<iostream>
#include<vector> 

1
2
#include<vector>
#include<iostream> 

(just an example.both complier)
Oct 26, 2021 at 1:13pm
the sequence of including headfiles may affect the success of compilation.
That's only the case if your headers are poorly-written. If only one order of inclusion is valid then probably one of those headers needs to include the other.

Standard headers do not care in which order they're included.
Oct 26, 2021 at 1:17pm
No, the ordering of standard library headers should not matter (assuming you don't have code in-between the #includes, then it would of course matter).

This might not be true in general for custom headers, where you could have, for example, a conflicting macro that bleeds into the other header.
Topic archived. No new replies allowed.