What are 'aliased' stream buffers?

佐手、 提交于 2019-12-07 15:37:23

问题


What are 'aliased stream buffers`? I encountered the term in a comment on an answer of mine.


回答1:


I've never heard the term before, but in the thread you cite, the person who used it also gave an example: two streams which use the same streambuf.

Of course, just because two streams don't use the same streambuf, doesn't mean that data written to them doesn't ultimately end up in the same place; that they don't alias the same sink, if that is what is meant. There are filtering streambuf's, which forward the actual sinking and sourcing to another streambuf, and on most systems, it's possible to open a file at the system level, and connect a streambuf (or two) to it.

-- James Kanze




回答2:


It means an object with different name, for example this:

ostream &lbw = cout;

lbw << "Shahid out" << "Sachin in" << endl; //goes to cout!



回答3:


What probably was meant in the comment there is this:

ofstream file;
file.rdbuf(cout.rdbuf());

// writes to cout
file << "hello";

So now the check there doesn't work:

if(&file == &cout)
    // no, it doesn't


来源:https://stackoverflow.com/questions/5296484/what-are-aliased-stream-buffers

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