您好,我目前正在通过初学者书籍学习 C++。作者在书中对istream
和ostream
这两个头文件做了简单的解释。可惜我不太明白他的意思。我试图在网上查找它们,但这并不能帮助我理解他的解释。
他说
istream
: Contains the extractors for inputting data from streams and includes the template classbasic_istream
. In other words,istream
puts the I in I/O.
ostream
: Contains the inserters for outputting a series of bytes and includes the templatebasic_istream
. basicallyostream
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/