Why in the below code without including “string” header I can declare string variable.
But compiler complains only for cout, when I try to print the string.
What information “string” header consists of ?
#include <iostream>
//#include "string"
int main ()
{
std::string str="SomeWorld";
std::cout<<str<<std::endl;
return 0;
}
Because the header defining
std::basic_stringis most likely (indirectly) included by<iostream>(std::stringis a typedef based onstd::basic_string<char>). The overload foroperator<<forstd::couthowever is only defined in<string>.