This is because the compiler processes headers in the order in which they appear in the main compilation unit.
Because the .cpp
file included <string>
(indirectly via "stdafx.h"
), the contents of <string>
are known to the compiler, and can be used by code that follows, even code pulled in from header files.
It is fragile though, because including your header file without first including <string>
will cause errors.