> '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:
1 2 3 4 5 6 7
|
#include <iostream>
int main()
{
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),
http://coliru.stacked-crooked.com/a/5e17d16542816ce2
but it generates an error with the Microsoft library on Windows:
(
operator<< for
std::string has not been pulled in by
#include <iostream>)
http://rextester.com/QWET28975
The sane thing to do is: if
std::string is to be used,
#include <string>