How is the object std::cout constructed/instantiated

后端 未结 1 1626
梦毁少年i
梦毁少年i 2021-02-06 15:45

So std::cout is an object. My doubt is how/where is it constructed/instantiated.

Thanks.

相关标签:
1条回答
  • 2021-02-06 16:28

    It's constructed by ios_base::Init. First time that object is created, cout and friends are created. If the last object is destroyed, cout and friends are flushed (calling .flush()).

    In C++0x it will be guaranteed that if you include <iostream>, and use of cout and friends after the #include will use constructed cout and friends objects. In C++03, it is said that

    The objects are constructed, and the associations are established at some time prior to or during first time an object of class ios_base::Init is constructed, and in any case before the body of main begins execution.

    0 讨论(0)
提交回复
热议问题