This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/11528] New: money_get does not get "$.00"
- From: "paul at serice dot net" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 15 Jul 2003 18:06:32 -0000
- Subject: [Bug c++/11528] New: money_get does not get "$.00"
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11528
Summary: money_get does not get "$.00"
Product: gcc
Version: 3.3
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: paul at serice dot net
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: i686-pc-linux-gnu
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu
I'm having a problem on gcc-3.2.3 and gcc-3.3 getting the money_get facet to
parse "$.00". It is happy with things like "$.01" though. (I haven't been able
to test it with anything more recent because I'm getting errors every time I try
to compile something from cvs.)
The problem is reproduced in the following code. After compiling, I run it as
LANG=en_US.UTF8 ./main
The output I get is
amount = 5
amount = 4
amount = 3
amount = 2
amount = 1
amount = <error>
The "<error>" corresponds to "$.00".
===================
#include <locale>
#include <string>
#include <sstream>
#include <iostream>
using namespace std;
namespace {
void doit(const string& amount)
{
// Use a non-trivial locale by setting LANG=en_US.UTF8 (for
// example).
istringstream istrm(amount);
istrm.imbue(locale(""));
// Retrieve the money_get facet.
const money_get<char>& mgf =
use_facet< money_get <char> >(istrm.getloc());
// Use the facet to extract the amount from istrm.
string extracted_amount;
ios_base::iostate err = ios_base::iostate(0);
mgf.get(istrm, 0, false, istrm, err, extracted_amount);
// Check for errors.
if( err & ios_base::failbit ) {
extracted_amount = "<error>";
}
// What did we get?
cout << "amount = " << extracted_amount << endl;
}
}
int main(int argc, char* argv[])
{
int rv = 0;
doit("$.05");
doit("$.04");
doit("$.03");
doit("$.02");
doit("$.01");
doit("$.00");
return rv;
}