C++ <istream> 和 <ostream>

标签 c++

您好,我目前正在通过初学者书籍学习 C++。作者在书中对istreamostream 这两个头文件做了简单的解释。可惜我不太明白他的意思。我试图在网上查找它们,但这并不能帮助我理解他的解释。

他说

istream: Contains the extractors for inputting data from streams and includes the template class basic_istream. In other words, istream puts the I in I/O.

ostream: Contains the inserters for outputting a series of bytes and includes the template basic_istream. basically ostream puts the O in I/O.

我不明白的是为什么您需要提取器来从流中输入数据,反之亦然ostream

最佳答案

作为程序输入的数据必须从提供它的 istream提取

同样,作为程序输出的数据必须插入ostream 中,以便将它带走。

+------------------+                  +-----------------------------------------+
| DATA SOURCE      |  ----input---->  | [istream] --extractor-->  YOUR PROGRAM  |
+------------------+                  +-----------------------------------------+

+------------------+                  +-----------------------------------------+
| DATA SINK        |  <---output----  | [ostream] <--inserter---  YOUR PROGRAM  |
+------------------+                  +-----------------------------------------+

关于C++ <istream> 和 <ostream>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24072124/

相关文章:

c# - ZeroMQ C# 客户端不接收来自 C++ 服务器的消息

c++ - 更改数组类以保存动态数组

c++ - 构建Qt应用程序时出错:/bin/sh: -c: line 1: syntax error: unexpected end of file

c++ - 当我尝试从 boost::regex_match(text, e) 捕获异常时,为什么会得到一个核心转储?

c++ - "Right"解除分配 std::vector 对象的方法

c++ - 对 "same"类型转换的不同结果感到困惑, float 到 int

c++ - C++ 中的私有(private)成员与临时变量

php - 在 PHP 上运行 C++ 可执行文件

c++ - 如何将QML模型更改为C++模型?

c++ - 优化 uint8 的最大递减量