Reputation: 48702
All C++ input and output streams have an associated locale; the std::ios_base::getloc()
method returns a std::locale
by value, so that value must have been set up during construction. The locale can be changed after construction of the stream, using the imbue()
mutator. But what is the default locale for a stream? What locale does a stream of the standard library classes (std::ofstream
, etc) have just after construction? And what is the locale of the standard streams (std::cout
, std:cerr
and std:log
) on program start?
The documentation I've seen for the stream constructors is unhelpful.
Upvotes: 3
Views: 1201
Reputation: 48702
The ultimate base class of all streams, std::basic_ios
, requires that the constructors of all streams call the initialization method std::basic_ios::init
. That method initializes the locale of the stream to be the locale given by the std::locale
default constructor. That default constructor constructs a copy of the "global locale", which is the "classic" locale by default, if the global locale has not been changed (using std::locale::global()
).
Hence, the default locale for all streams will usually be the "classic" locale.
Upvotes: 7