Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Can a locale be Removed from a basic_ostream Subsequent to basic_ostream.imbue(locale)

Can a locale be Removed from a basic_ostream Subsequent to basic_ostream.imbue(locale)

Scheduled Pinned Locked Moved C / C++ / MFC
c++csslearning
4 Posts 2 Posters 18 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    BernardIE5317
    wrote on last edited by
    #1

    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;

    Mircea NeacsuM 1 Reply Last reply
    0
    • B BernardIE5317

      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;

      Mircea NeacsuM Offline
      Mircea NeacsuM Offline
      Mircea Neacsu
      wrote on last edited by
      #2

      _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

      B 1 Reply Last reply
      0
      • Mircea NeacsuM Mircea Neacsu

        _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

        B Offline
        B Offline
        BernardIE5317
        wrote on last edited by
        #3

        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.

        Mircea NeacsuM 1 Reply Last reply
        0
        • B BernardIE5317

          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.

          Mircea NeacsuM Offline
          Mircea NeacsuM Offline
          Mircea Neacsu
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups