How are iostream objects cin, cout, cerr, and clog implemented?

别等时光非礼了梦想. 提交于 2019-12-04 19:26:12

There's no compiler magic.

IIRC, the standard implementation is to define a global constant object in the header. In each translation unit this header is included, one such object is created. Its constructor increments a counter, its destructor decrements it. When incrementing from 0 to 1, the the console stream objects are created, when decrementing from 1 to 0, they are destroyed.

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