iostream vs ostream what is different?

前端 未结 5 1919
孤街浪徒
孤街浪徒 2020-12-31 04:07

As the book says (Exploring C++: The Programmer\'s Introduction to C++):

The istream header declares input operators (>>), and ostream declares outp

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-31 04:49

    I can perfectly run that code without adding #include ostream;

    You happen to be able to on your specific installation. Upgrade your toolchain and that may no longer be the case.

    As of C++11 you can assume it for iostream/ostream, but there are other similar scenarios which C++11 does not cover.

    So, a general rule of thumb: whenever you use a standard library feature, include the header where it's declared/defined, rather than making assumptions and shortcuts.

提交回复
热议问题