Reputation: 601
#include <sstream>
using namespace std;
int main()
{
cout << "hi"; // error: undeclared cout
}
From what I have read, sstream class is derived from iostream class but why does it not get included automatically?
Upvotes: 3
Views: 477
Reputation: 180295
std::sstream
is derived from both std::istream
and std::ostream
. That means you don't need to include <istream>
or <ostream>
. However, std::cout
is defined in neither of those two headers. That's why you need yet another header, <iostream>
.
Upvotes: 1
Reputation: 147036
The iostream
-based classes are not the same as the iostream
header. Standard headers do not have to include each other, or may include each other in any order. If you wish to use the contents of <iostream>
, you must #include <iostream>
.
Upvotes: 11