11528 – money_get does not get "$.00" (original) (raw)

Description Paul Serice 2003-07-15 18:06:29 UTC

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 "" corresponds to "$.00".

===================

#include #include #include #include

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; }