home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c++.moderated      Moderated discussion of C++ superhackery      33,346 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 33,316 of 33,346   
   Martin B. to All   
   Re: std::to_string(int) deviates from io   
   27 Apr 14 23:11:22   
   
   From: 0xCDCDCDCD@gmx.at   
      
   On 24.04.2014 01:05, Daniel Krügler wrote:   
   > On 2014-04-16 17:18, Martin Ba wrote:   
   >>   
   >> I've noticed something interesting in the specification of   
   >> [std::to_string][1]:   
   >>   
   >> It is defined in terms of std::sprintf and outputting a number with   
   >> sprintf is *not* the same as using `operator<<` on a stream.   
   >   
   > Correct. The idea behind specifying the to_(w)string overloads was to   
   > provide a convenience function to allow the creation of a simple string   
   >> ... ... ...   
   >> Was this design choice deliberate?   
   >   
   > Yes, it was. There was never the intention to ensure equal behaviour of   
   > IO stream output and std::to_string result.   
   >   
   >> Would you think it is a problem?   
   >   
   > I don't see such a problem. You should only use the to_string functions   
   > if you do not depend on the effects of locales.   
   >   
      
   I feel I should respond to this.   
      
   AFAIKS, my example of to_string(int) is indeed locale independent,   
   because printf doesn't use any locale data for int. But to_string(float)   
   will always be locale dependent, because it needs (at least) a decimal   
   separator, so I was wondering why not go the whole way: That is to say,   
   use the only other thing that stock iostreams has over printf and that   
   is the thousand-separator/grouping.   
      
   Well I guess it's not a big deal. Certainly not a bigger deal than that   
   stock printf and stock iostreams differ on this factet of using locales   
   to start with.   
      
   cheers,   
   Martin   
      
      
   --   
         [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
         [ comp.lang.c++.moderated.    First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca