 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Mark Brown Guest
|
Posted: Sun May 13, 2007 2:39 am Post subject: help with money_get |
|
|
I am trying to understand how to correctly use the money_get facet
from the standard library. I have been experimenting with the example
program from the Apache stdcxx but I am having trouble getting it to
produce the same output on other implementations of the standard
library. The stdcxx output is:
$1,234.6789 --> "123467" --> 123467
but when I compile it with g++ I get:
$1,234.6789 --> "" --> 0
The facet fails to extract the monetary value. I also tried the latest
STLport with the same result. After removing the last two fractional
digits from the input string "$1,234.6789" all three libraries produce
the same output. Can someone explain what's going on? Is it a bug in g+
+ and STLport?
The example code is on this page:
http://incubator.apache.org/stdcxx/doc/stdlibref/money-get.html#sec12
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
Mark Brown Guest
|
Posted: Thu May 17, 2007 8:23 am Post subject: Re: help with money_get |
|
|
{ Edits: quoted signature and quoted clc++m banner removed. Tip: most
newsreader programs do that automatically (Google doesn't). -mod }
On May 15, 2:03 pm, Ulrich Eckhardt <eckha...@satorlaser.com> wrote:
| Quote: | Mark Brown wrote:
I am trying to understand how to correctly use the money_get facet
from the standard library. I have been experimenting with the example
program from the Apache stdcxx but I am having trouble getting it to
produce the same output on other implementations of the standard
library. The stdcxx output is:
$1,234.6789 --> "123467" --> 123467
but when I compile it with g++ I get:
$1,234.6789 --> "" --> 0
The facet fails to extract the monetary value. I also tried the latest
STLport with the same result. After removing the last two fractional
digits from the input string "$1,234.6789" all three libraries produce
the same output. Can someone explain what's going on? Is it a bug in g+
+ and STLport?
The example code is on this page:
http://incubator.apache.org/stdcxx/doc/stdlibref/money-get.html#sec12
I've been looking at this example and two questions came up:
1. It does a
return !(std::ios_base::eofbit == state);
in order to determine the success, but I don't think this is right. The
reason is that if it reads the whole input sequence, it should have set the
eof-bit (I think, I'd have to look it up, too). Also, I wonder if the
non-Apache implementations claim success or do they at least signal
failure? The reason is that locales are very dependant on the system, and I
know that on my desktop PC here this code will never work because it's OS
doesn't use locales of the form en_US.
|
You're right, stdcxx sets eofbit in state so main returns 0. The other
two libraries set both eofbit and failbit, so main returns 1 as a
failure as the comment in the code says.
| Quote: |
2. What does the inverse procedure produce? What is the output if you invoke
money_put accordingly?
|
The output of both 123467.89 and std::string("123467.89") using
money_put::put() is the same for all three libraries: 123,467.89.
It looks like g++ and STLport reject the input only because of the
extra decimal digits. That doesn't seem right but I'm not an expert on
locales.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
sebor@roguewave.com Guest
|
Posted: Mon May 21, 2007 11:19 am Post subject: Re: help with money_get |
|
|
On May 15, 2:03 pm, Ulrich Eckhardt <eckha...@satorlaser.com> wrote:
[...]
| Quote: | The example code is on this page:
http://incubator.apache.org/stdcxx/doc/stdlibref/money-get.html#sec12
I've been looking at this example and two questions came up:
1. It does a
return !(std::ios_base::eofbit == state);
in order to determine the success, but I don't think this is right. The
reason is that if it reads the whole input sequence, it should have set the
eof-bit (I think, I'd have to look it up, too).
|
It does. The example returns 0 on success (i.e., when eofbit is set),
and 1
on failure. I belive Mark is correct: both g++ and STLport are wrong
here.
FWIW, you shouldn't need the exact same locale to reproduce the
behavior.
Pretty much any locale should do, including French, German, or
Spanish.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
Powered by phpBB © 2001, 2006 phpBB Group
|