Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
This post was edited and submitted for review 2 years ago and failed to reopen the post:
Original close reason(s) were not resolved
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(1)
C++ 程序的运行假设是该程序具有一个输入源(可通过 cin 访问)和两个输出流,一个用于常规输出(可通过 cout 访问),另一个用于报告错误(可通过
cerr
访问)。(还有
clog
,它类似于cout
,但它不缓冲其输出。我几乎从未见过它在实践中使用过)。因为
cin
仅用于输入,因此您可以使用它来读取值,但不能用于写入值。同样,您可以写入cout
和cerr
,但无法读取它们。我猜测(?)C++ 没有将所有这些组合成一个源(假设的“
调用
”),因为具有两个不同的输出流和一个输入流的不对称性。尽管原则上这是可以做到的。C++ programs operate under the assumption that the program has one input source (accessible via
cin
) and two output streams, one for regular output (accessible viacout
) and one for reporting errors (accessible viacerr
).(There's also
clog
, which is likecout
but which doesn't buffer its output. I've almost never seen it used in practice).Because
cin
is just for input, you can use it to read values but not for writing values. Similarly, you can write tocout
andcerr
, but you can't read from them.I'm guessing (?) that C++ didn't combine all of these into a single source (a hypothetical "
call
") because of the asymmetry of having two different output streams and one input stream. Though in principle it would have been possible to do this.