Hi, Status update, I didn't have time to look into this too deep into my previous matter so I downgraded my system and the locale works smoothly. Now I have come to a problem with the money_get facet and made a sample program displaying my problems (see below). In the output you can see: "123,00" - error parsing: (state==6) parsed= "123,00 " = 12300 What is the problem here? Why does money_get need an ending space? Thank you in advance, BRGDS, Jens Berlips ============== c++ code ================ #include <stdio.h> #include <stdlib.h> #include <locale> #include <errno.h> #include <iostream> #include <sstream> void output(const std::string &strinp) { std::cout << """ << strinp << "\""; #ifdef WIN32 std::locale loc = std::locale("Swedish_sweden.OCP"); #else std::locale loc("sv_SE"); #endif std::ios_base::iostate state = std::ios_base::goodbit; std::string str; typedef std::istreambuf_iterator<char> iter_t; // input std::istringstream stream(strinp); stream.imbue(loc); // stream.setf(std::ios_base::showbase); // showbase is set => base is not optional. std::istream::sentry guard(stream); if(guard) { // iterators: iter_t eos; iter_t bos(stream); const std::money_get<char> &mp = std::use_facet<std::money_get<char> >(loc); iter_t end1 = mp.get(bos, eos, false, stream, state, str); if(state ==0 || state == std::ios_base::eofbit) { long int i = strtol(str.c_str(), 0,0); if(errno == ERANGE) { std::cout << " - error strotl" << std::endl;; } else { std::cout << " = " << i << std::endl; } } else { std::cout << " - error parsing: " << str << " (state==" << state << ") parsed=" << str << std::endl; } } else { std::cout << "sentry failed" << std::endl; } } int main(int argv, char **argc) { output("123,00 kr"); output("123,00"); output("123,00 "); output("123"); output("123 "); output(",10"); output(",10 kr"); output("0,12"); output("0,12 kr"); int a; std::cin >> a; return 1; } /* visual studio .net 8.0 output: "123,00 kr" = 12300 "123,00" = 12300 "123,00 " = 12300 "123" = 12300 "123 " = 12300 ",10" = 10 ",10 kr" = 10 "0,12" = 10 "0,12 kr" = 10 (bugs here include invalid iterator dereferencing, but it gets the money correctly/ gcc version 4.1.2 20061115 (prerelease) (Debian 4.1.1-21) with: libstdc++6-4.1-dev 4.1.1-21 "123,00 kr" = 12300 "123,00" - error parsing: (state==6) parsed= "123,00 " = 12300 "123" - error parsing: (state==6) parsed= "123 " - error parsing: (state==6) parsed= ",10" - error parsing: (state==6) parsed= ",10 kr" = 10 "0,12" - error parsing: (state==6) parsed= "0,12 kr" = 12 */ ====================================== On 6/21/07, Jens Berlips <jens.berlips@xxxxxxxxx> wrote:
Hi All, I recently updated gcc to the newest version in debian unstable and suddenly all c++ locale stopped working but the old-fashion c-api still works. OK == p = setlocale(LC_ALL, "en_US"); lc = localeconv(); std::cout << lc->decimal_point << std::endl; NOT OK (throws runtime_error) ======================= std::locale loc("en_US"); output: [[ terminate called after throwing an instance of 'std::runtime_error' what(): locale::facet::_S_create_c_locale name not valid Aborted ]] What am I doing wrong with my locales? OBS: std::locale loc("C") is also ok. System info ========= The output of "locale -a" includes "en_US", it has been generated using locale-gen, the gcc-4.1-locales, and gcc-4.2-locales packages are both installed. I have tried: ii g++-4.1 4.1.2-12 The GNU C++ compiler ii g++-4.2 4.2-20070609-1 The GNU C++ compiler (for an output of g++ -v see (3) below) They both give the same problem. For an output of "ldd" see (1) below. The source code of my test application h1.cpp can be seen below (2). Debugging libstdc++ =============== I have tried to debug the libstdc++ library, but gdb doesn't allow me to step inside the libstdc++ library functions (ex. std::locale constructor), im using: g++ -D_GLIBCXX_DEBUG -g -Wall h1.cpp -o h1 to compile my program. The debug library has been installed. ii libstdc++6-4.1-dbg 4.1.2-12 The GNU Standard C++ Library v3 (debugging f What is the correct way to compile my program to be able to debug "inside" libstdc++, that is, not only the headers (then -g is enough)? Thanks in advance! Best regards, Jens ========================================== ---- (1) ---- ldd -v ./h1 linux-gate.so.1 => (0xffffe000) libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0xb7e94000) libm.so.6 => /lib/libm.so.6 (0xb7e6d000) libgcc_s.so.1 => /lib/libgcc_s.so.1 (0xb7e62000) libc.so.6 => /lib/libc.so.6 (0xb7d1f000) /lib/ld-linux.so.2 (0xb7f88000) Version information: ./h1: libgcc_s.so.1 (GCC_3.0) => /lib/libgcc_s.so.1 libstdc++.so.6 (CXXABI_1.3) => /usr/lib/libstdc++.so.6 libstdc++.so.6 (GLIBCXX_3.4) => /usr/lib/libstdc++.so.6 libc.so.6 (GLIBC_2.0) => /lib/libc.so.6 libc.so.6 (GLIBC_2.1.3) => /lib/libc.so.6 libc.so.6 (GLIBC_2.2) => /lib/libc.so.6 /usr/lib/libstdc++.so.6: ld-linux.so.2 (GLIBC_2.3) => /lib/ld-linux.so.2 libgcc_s.so.1 (GLIBC_2.0) => /lib/libgcc_s.so.1 libgcc_s.so.1 (GCC_3.3) => /lib/libgcc_s.so.1 libgcc_s.so.1 (GCC_3.0) => /lib/libgcc_s.so.1 libc.so.6 (GLIBC_2.3) => /lib/libc.so.6 libc.so.6 (GLIBC_2.1) => /lib/libc.so.6 libc.so.6 (GLIBC_2.1.3) => /lib/libc.so.6 libc.so.6 (GLIBC_2.2) => /lib/libc.so.6 libc.so.6 (GLIBC_2.0) => /lib/libc.so.6 /lib/libm.so.6: ld-linux.so.2 (GLIBC_PRIVATE) => /lib/ld-linux.so.2 libc.so.6 (GLIBC_2.1.3) => /lib/libc.so.6 libc.so.6 (GLIBC_2.0) => /lib/libc.so.6 /lib/libgcc_s.so.1: libc.so.6 (GLIBC_2.1.3) => /lib/libc.so.6 libc.so.6 (GLIBC_2.2.4) => /lib/libc.so.6 libc.so.6 (GLIBC_2.0) => /lib/libc.so.6 /lib/libc.so.6: ld-linux.so.2 (GLIBC_PRIVATE) => /lib/ld-linux.so.2 ld-linux.so.2 (GLIBC_2.3) => /lib/ld-linux.so.2 ld-linux.so.2 (GLIBC_2.1) => /lib/ld- linux.so.2 ---- (2) ---- #include <locale.h> #include <locale> #include <iostream> int main(int argv, char **argc) { char *p; lconv *lc; // std::locale loc("en_US"); // fails p = setlocale(LC_ALL, "en_US"); lc = localeconv(); std::cout << lc->decimal_point << std::endl; return 0; } ---- (3) ----- g++ -v Using built-in specs. Target: i486-linux-gnu Configured with: ../src/configure -v --enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.1.3 --program-suffix=- 4.1 --enable-__cxa_atexit --enable-clocale=gnu --enable-libstdcxx-debug --enable-mpfr --with-tune=i686 --enable-checking=release i486-linux-gnu Thread model: posix gcc version 4.1.3 20070601 (prerelease) (Debian 4.1.2-12 )