To have a less controversial example, consider this code:
#include <iostream>
int main() {
std::string s{"asd"};
std::cout << s;
}
It compiles without error here https://godbolt.org/z/fWbK4Yc5z.
If you use std::string
you should include string
. That does not imply that you can rely on an error when the include is missing. Standard library headers can include other headers. Here it happens that iostream
apparently includes string
. This is nothing to rely on. It may change with the next version of the compiler (I used gcc), and it can break on a different compiler.
The (inofficial) rule is: Include what you use. If you use std::string
you should include string
. If you use INT_MIN
you should include climits
.