Difference between basic_istream<>::tellg() and basic_ostream<>::tellp() [closed]

巧了我就是萌 提交于 2019-12-08 15:27:30

问题


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<> ?


回答1:


And how would you distinguish them in bidirectional streams, like std::fstream or std::stringstream? Streams are allowed to maintain separate pointers for input and output: fstream doesn't, but stringstream does. So you need either a flag to indicate which one you want (as is the case in streambuf), or you need two separate functions.




回答2:


tellg() get the position of the get pointer and tellp() gets the position of the put pointer, one of them is the place where you read and the second- where you write in the file. So the two functions do different things and return different values. Why would you think they should have the same name?



来源:https://stackoverflow.com/questions/14522122/difference-between-basic-istreamtellg-and-basic-ostreamtellp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!