5

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

Thanks.

Vikas
  • 8,790
  • 4
  • 38
  • 48
  • 2
    In the library somewhere that you don't have easy access to. Remember that you're not guaranteed anything about *how* it's constructed, just that it is and what it'll do – Robert Dec 16 '10 at 05:48

1 Answers1

4

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.

Johannes Schaub - litb
  • 496,577
  • 130
  • 894
  • 1,212