Why is the iostream header file not included?

#include <sstream>
using namespace std;

int main()
{
    cout << "hi"; // error: undeclared cout
}

From what I read, the sstream class is derived from the iostream class, but why doesn't it turn on automatically?

+3
source share
2 answers

Classes iostreamdo not match the title iostream. Standard headings should not include each other or may include each other in any order. If you want to use the content <iostream>, you must #include <iostream>.

+11
source

std::sstreamIt is deduced both from std::istream, and std::ostream. This means that you do not need to include <istream>or <ostream>. However, std::coutit is not defined in either of these two headings. You need one more heading for this <iostream>.

+1
source

All Articles