What are 'aliased' stream buffers?

ε祈祈猫儿з 提交于 2019-12-05 23:18:54
James Kanze

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

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

ostream &lbw = cout;

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

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