Can a locale be Removed from a basic_ostream Subsequent to basic_ostream.imbue(locale)
-
Greetings Kind Regards Please consider the C++ code below. It is utilized it to generate a locale formatted number e.g. "1,234". However subsequent I wish again to generate a number but not so formatted e.g. "1234". So I inquire can an imbued locale be removed from an output stream so no such locale specific formatting occurs. Of course another stream which has not been so imbued can be utilized for this purpose but prefer not to do so as such seems a less elegant solution. Thank You Kindly
basic_ostringstream _ostream;
_ostream.imbue(locale("en-US"));
_ostream << 1234; -
Greetings Kind Regards Please consider the C++ code below. It is utilized it to generate a locale formatted number e.g. "1,234". However subsequent I wish again to generate a number but not so formatted e.g. "1234". So I inquire can an imbued locale be removed from an output stream so no such locale specific formatting occurs. Of course another stream which has not been so imbued can be utilized for this purpose but prefer not to do so as such seems a less elegant solution. Thank You Kindly
basic_ostringstream _ostream;
_ostream.imbue(locale("en-US"));
_ostream << 1234;_ostream.imbue(std::locale::classic());
If you want to be standard abiding, names prefixed with "_" are reserved in global namespace. I can hear "man, is this guy pedantic!" :laugh:
Mircea
-
_ostream.imbue(std::locale::classic());
If you want to be standard abiding, names prefixed with "_" are reserved in global namespace. I can hear "man, is this guy pedantic!" :laugh:
Mircea
May I please inquire how you would name the variable. It is my custom to utilize prefix '_' for identifiers of objects of standard template library types for brief simple functions as the purpose of such object is obvious in such situations instead of a lengthy explanatory name which I reserve for more lengthy more complicated functions.
-
May I please inquire how you would name the variable. It is my custom to utilize prefix '_' for identifiers of objects of standard template library types for brief simple functions as the purpose of such object is obvious in such situations instead of a lengthy explanatory name which I reserve for more lengthy more complicated functions.
It's a question of taste: put the underscore at the other end (
ostream_
), or come up with a different name (ostrm
). As in any question of taste, there isn't any right answer; my personal preference goes for trailing underscore. The rule about leading underscore is not my invention. See C++ Language standard section 17.6.4.3.2 - Global names (page 429).Mircea