[OpenIndiana-discuss] strange error

Apostolos Syropoulos asyropoulos at yahoo.com
Sun Jun 26 20:09:28 UTC 2011



 Hello,

 Today someone posted a message to the gcc-help mailing list. He complained
because he could not use Unicode characters in a C++ program. He posted a
program and some list members suggested a modification. The modified program
follows:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
  wstring ws2 = L"Euro:\x20ac";
  wofstream out("unicode.txt");
  out.imbue(locale("el_GR.UTF-8"));
  out << ws2<< endl;
}

I have no idea what platform he uses but I get the following error
message when running the g++ generated binary:

terminate called after throwing an instance of 'std::runtime_error'
  what():  locale::facet::_S_create_c_locale name not valid
Abort (core dumped)

But when I compile with solstudio the program terminates normally
but file unicode.txt is empty (i.e., its size is zero). On Linux
this program runs just fine and creates a file that contains the
Euro character. According to another poster to gcc-helo, on MacOS
people get exactly the same error. I guess something is wrong, but
I have no idea what's wrong. BTW, I have tried to use en_US.UTF-8
instead of el_GR.UTF-8 but this did not make any difference.

A.S.


----------------------
Apostolos Syropoulos
Xanthi, Greece



More information about the OpenIndiana-discuss mailing list