问题描述
我只是想知道为什么basic_istream<>
类中定义的成员函数tellg()
和basic_ostream<>
类中定义的tellp()
具有不同的名称.那是因为basic_fstream<>
是从basic_istream<>
和basic_ostream<>
派生的吗?
I was just wondering why the member functions tellg()
defined in basic_istream<>
class and tellp()
defined in basic_ostream<>
class have different names. Is that because basic_fstream<>
is derived from basic_istream<>
and basic_ostream<>
?
推荐答案
以及如何在双向流中区分它们,例如std::fstream
或std::stringstream
?允许流维护输入和输出的单独指针:fstream
不会,但是stringstream
会.所以你需要一个标志指出您想要的那个(例如streambuf
),或者您需要两个单独的功能.
And how would you distinguish them in bidirectional streams,like std::fstream
or std::stringstream
? Streams are allowedto maintain separate pointers for input and output: fstream
doesn't, but stringstream
does. So you need either a flag toindicate which one you want (as is the case in streambuf
), oryou need two separate functions.
这篇关于basic_istream<> :: tellg()和basic_ostream<> :: tellp()之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!