C ++流混乱:istreambuf_iterator vs istream_iterator? [英] C++ streams confusion: istreambuf_iterator vs istream_iterator?
问题描述
istreambuf_iterator
和 istream_iterator
之间有什么区别?
和一般stream和streambufs之间的区别是什么?
我真的找不到任何清楚的解释,所以决定这里问。
What is the difference between istreambuf_iterator
and istream_iterator
?
And in general what is the difference between streams and streambufs?
I really can't find any clear explanation for this so decided to ask here.
推荐答案
IOstreams使用streambufs作为其输入/输出的源/目标。有效地,streambuf-family做所有关于IO的工作,IOstream-family只用于格式化和字符串/字符串转换。
IOstreams use streambufs to as their source / target of input / output. Effectively, the streambuf-family does all the work regarding IO and the IOstream-family is only used for formatting and to-string / from-string transformation.
现在, a href =http://en.cppreference.com/w/cpp/iterator/istream_iterator> istream_iterator
采用模板参数,说明未格式化来自streambuf的字符串序列应该格式化为,像 istream_iterator< int>
会将所有传入的文本解释为($空格分隔) int
s。
Now, istream_iterator
takes a template argument that says what the unformatted string-sequence from the streambuf should be formatted as, like istream_iterator<int>
will interpret (whitespace-delimited) all incoming text as int
s.
另一方面, istreambuf_iterator
只关心原始字符,并直接在 istream
的相关streambuf上进行迭代
On the other hand, istreambuf_iterator
only cares about the raw characters and iterates directly over the associated streambuf of the istream
that it gets passed.
一般来说,如果你只对原始字符感兴趣,可以使用 istreambuf_iterator
。如果您对格式化的输入感兴趣,请使用 istream_iterator
。
Generally, if you're only interested in the raw characters, use an istreambuf_iterator
. If you're interested in the formatted input, use an istream_iterator
.
我所说的也适用于 ostream_iterator
和 ostreambuf_iterator
。
All of what I said also applies to ostream_iterator
and ostreambuf_iterator
.
这篇关于C ++流混乱:istreambuf_iterator vs istream_iterator?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!