user756327
user756327

Reputation: 601

why does iostream header file not get included?

#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

Answers (2)

MSalters
MSalters

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

Puppy
Puppy

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

Related Questions