On Mon, 2011-06-27 at 22:31 +0100, Jonathan Wakely wrote: > On 27 June 2011 21:57, eric <fsshl@xxxxxxx> wrote: > > On Mon, 2011-06-27 at 18:28 +0100, Jonathan Wakely wrote: > >> On 27 June 2011 17:35, eric wrote: > >> > On Mon, 2011-06-27 at 17:03 +0100, Jonathan Wakely wrote: > >> >> On 27 June 2011 16:39, eric <fsshl@xxxxxxx> wrote: > >> >> > Dear advanced c/g++ programers: > >> >> > after I copied and compiled last email's code > >> >> > I tested it, with your suggestion (put POSIX and C behind it), they > >> >> > run (generate locale), > >> >> > but > >> >> > all test failed to make output file with size > 0 > >> >> > so if you can plz help again, and thank a lot in advance, Eric > >> >> > > >> >> > ------------------------------------------------------------ > >> >> > eric@eric-laptop:~/cppcookbook$ ./a.out > >> >> > trying to access locale el_GR.utf8 > >> >> > Couldn't generate locale el_GR.utf8: locale::facet::_S_create_c_locale > >> >> > name not valid > >> >> > Error when writing to file > >> >> > >> >> As shown by 'locale -a' you don't have the el_GR.utf8 locale > >> >> installed, so obviously this won't work. > >> >> > >> >> > eric@eric-laptop:~/cppcookbook$ ls -l -a unicode.txt > >> >> > -rw-r--r-- 1 eric eric 0 2011-06-27 08:31 unicode.txt > >> >> > eric@eric-laptop:~/cppcookbook$ ./a.out POSIX > >> >> > trying to access locale POSIX > >> >> > Generated locale C > >> >> > Error when writing to file > >> >> > eric@eric-laptop:~/cppcookbook$ ./a.out C > >> >> > trying to access locale C > >> >> > Generated locale C > >> >> > Error when writing to file > >> >> > eric@eric-laptop:~/cppcookbook$ ./a.out B > >> >> > trying to access locale B > >> >> > Couldn't generate locale B: locale::facet::_S_create_c_locale name not > >> >> > valid > >> >> > Error when writing to file > >> >> > eric@eric-laptop:~/cppcookbook$ > >> >> > ------------------------------------------------------- > >> >> > >> >> > >> >> Did you ever answer the question of which OS you're using? > >> >> > >> >> Your gcc is using --enable-clocale=generic so doesn't support named > >> >> locales in the C++ library. > >> >> > >> >> You could try running your code with a different global locale, i.e. > >> >> > >> >> LANG=en_US.utf8 ./a.out > >> > ---------------------------------------------------------------- > >> > thanks your suggestion, > >> > here is the result of my test on your suggestion and what kind of I use > >> > ---- > >> > eric@eric-laptop:~/cppcookbook$ LANG=en_US.utf8 ./a.out > >> > trying to access locale el_GR.utf8 > >> > Couldn't generate locale el_GR.utf8: locale::facet::_S_create_c_locale > >> > name not valid > >> > Error when writing to file > >> > eric@eric-laptop:~/cppcookbook$ uname -r > >> > 2.6.35-25-generic > >> > eric@eric-laptop:~/cppcookbook$ > >> > (Ubuntu/linux 10.04 upgrade kernel to 2.6.35-25) > >> > >> Your GCC seems to be using --enable-clocale=generic on GNU/Linux, > >> which makes no sense. > >> > >> What does 'gcc -v' print? > >> > >> > I also modify from el_GR to en_US in en_US.utf8 > >> > then ./a.out (or LANG=en_US.utf8 ./a.out , same error) > >> > trying to access locale en_US.utf8 > >> > Couldn't generate locale en_US.utf8: locale::facet::_S_create_c_locale > >> > name not valid > >> > Error when writing to file > >> > >> This will not work, you cannot load any named locale with your version of gcc. > >> > >> My suggestion is to run the original program to write unicode to file > >> (not this test program) with LANG=en_US.utf8 > > ---------------------------------------------------------- > > eric@eric-laptop:~/cppcookbook$ gcc -v > > Using built-in specs. > > COLLECT_GCC=gcc > > COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/i686-pc-linux-gnu/4.5.2/lto-wrapper > > Target: i686-pc-linux-gnu > > Configured with: ./configure > > Thread model: posix > > gcc version 4.5.2 (GCC) > > eric@eric-laptop:~/cppcookbook$ > > ----------------------------------------------------------------- > > there indeed is another way to write unicode to outfile in my current g > > ++(similar as vc++ 2005), > > but I like to know why > > outfile << ws2 << endl; > > > > which according to book work in CodeWarrior, can not work in my system > > (gcc/g++/linux)?(file length 0 or show 0 at outfile.good()) > > Because your locale isn't set appropriately, How to make my system's local set appropriately? > and you don't seem to be > able to make it use a named locale. And Make my system to use named locale? > > Codewarrior is not gcc, and old C++ code involving unicode is not > standard or portable, so it's not a surprise if the same code doesn't > work everywhere. Need and thanks c/g++ advance programer's help again and a lot in advance, Eric