Language localization with streams under C++

LLeweLLyn Reese llewelly@lifesupport.shutdown.com
Mon Jul 21 17:10:00 GMT 2003


"Heilmann, Thomas (GE51)" <thomas.heilmann@honeywell.com> writes:

> Hello,
> 
> may be you can help me with my problem about language localization.
> 
> As I read in the documentation, for example "setlocale( LC_ALL, "German" );"
> is the common way to set the language localization. But this will be valid
> for
> the whole program and it is not that what I want and need.
> 
> While programming with C++, there's the possibility to create a "locale"
> object
> and imbue a stream with it. Then this language localization is only valid
> for
> this stream and its life cycle. That is what I want and need.
> 
> Here a small example:
>    std::ofstream OutFile;
>    std::locale Local_German( "German" );
>    OutFile.imbue( Local_German );
> 
> My problem is now, that this code is compilable, but while the program is
> running
> and would create this object 'Local_German', it crashes.
> I checked this with several locale strings like "C", "", "English" and some
> more.
> With the first two, the locale object is created well and the program is
> running well.

You must have glibc 2.2.5 or newer for C++ locale support to
    work. Also, I do not know if a German locale is supported in
    C++. (Nor do I know where to find out.) What I have heard is that
    3.2 supports only C and English locales, however I cannot find
    official verification of this.



More information about the Gcc-help mailing list