iostream vs ostream有什么不同? [英] iostream vs ostream what is different?

查看:200
本文介绍了iostream vs ostream有什么不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如书所述(探索C ++:程序员对C ++的介绍);

istream头声明输入运算符(>>),ostream声明输出运算符(<<)。

我可以完美运行该代码,但不添加#include ostream;

As book says (Exploring C++: The Programmer's Introduction to C++);
The istream header declares input operators (>>), and ostream declares output operators(<<).
I can perfectly run that code without adding #include ostream;

#include <iostream>
using namespace std;
int main()
{
  cout << "hello world"<< endl;
  return 0;
}

但在本书的例子中,如

But in book's example like

#include <iostream>
#include <ostream>    //why?
using namespace std;
int main()
{
  cout << "hello world"<< endl;
  return 0;
}

那么iostream,ostream,istream是头文件吗?

如果ostream不是必需的(iostream使作业)为什么作者包括它在例子中?或者为什么 ostream头文件仍然存在

So iostream,ostream,istream are header files right?
If ostream is not necessary (iostream makes the jobs) why author include it in example? Or why ostream header file still exist?

注意:在Bruce Eckel的Vol 1 2000)没有关于 ostream或istream 的信息。只有一个头文件 iostream

Note: In Bruce Eckel's Vol 1 book (which is published in 2000) there is nothing about ostream or istream. Only one header file which is iostream.

推荐答案

我发送电子邮件到Bjarne Stroustrup,他回答如下:


就我个人而言,我总是使用 iostream ,你永远不需要两者。 存在,以便人们可以#include只需要最小的声明。

So After that; I sent email to Bjarne Stroustrup and He replied just like that:
Personally, I always use iostream and you never need both. ostream exists so that people can #include only the minimaldeclaration needed.

这篇关于iostream vs ostream有什么不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆