简体   繁体   中英

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?

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> .

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> .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM