> 'm able to use all the string functionality in my program even though I have not declared
> #include <string> in my program.
One standard library header may include all or parts of other standard library headers. There is no bending of the rules; it is expressly permitted by the standard.
For example, if we include the header <fstream>
, we get (at least) the declarations of the constructors of file streams which has a parameter of type const std::string&
; for that header to be compileable, at least the declaration of std::string
would have to be available.
You may not be able to use all
the string functionality if you do not #include <string>
For example, consider this program:
const std::string str = "hello world!\n" ;
std::cout << str ;
It compiles cleanly with the GNU and LLVM libraries on Linux (note that neither library is 'quietly bending' the rules),
but it generates an error with the Microsoft library on Windows:
has not been pulled in by #include <iostream>)
The sane thing to do is: if std::string
is to be used, #include <string>