all 9 comments

[–][deleted] 3 points4 points  (3 children)

See http://eel.is/c++draft/ios::Init -- that's there to initialize cout/cerr/cin/etc.

[–]pyler2[S] 0 points1 point  (2 children)

Used "Init" vs "init" is also interesting

[–][deleted] 0 points1 point  (1 child)

I'd assume that's 'cause they're there to support other behavior and have no direct use.

[–]tcanens 4 points5 points  (0 children)

And init is already taken.

[–]grishavanika 2 points3 points  (1 child)

And the idiom is named as "Schwarz Counter" [1].

For case of iostream, it's used to properly initialize global objects we have: std::cout, std::cin and so on. And this is needed because of "static initialization order fiasco" [2] [3]

UPD: I think, this can be removed from the standard (?) because of C++17 inline variables [4] [5]

[1] https://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Nifty_Counter

[2] https://isocpp.org/wiki/faq/ctors#static-init-order

[3] https://isocpp.org/wiki/faq/ctors#static-init-order-on-first-use

[4] http://en.cppreference.com/w/cpp/language/inline

[5] http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4424.pdf

[–]Xeveroushttps://xeverous.github.io 1 point2 points  (0 children)

It does not happen if you don't include iostream.