HighTechTalks DotNet Forums  

C++ locale and .NET -> conversion error running in .NET-environmen

Dotnet Internationalization microsoft.public.dotnet.internationalization


Discuss C++ locale and .NET -> conversion error running in .NET-environmen in the Dotnet Internationalization forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
RainerK
 
Posts: n/a

Default C++ locale and .NET -> conversion error running in .NET-environmen - 08-24-2006 , 07:43 AM






Hi,

running the following code as an console application:

#include <locale>
#include <iostream>
#include <sstream>
#include <tchar.h>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
// ----------------------------------------
const char* arrLocaleNames[] = {
"German_germany",
"german-austrian",
"german-swiss",
"german-austrian",
"C",
"French",
"",
};
ostringstream* poStrStream = new ostringstream;
*poStrStream << "output of double a=1234.56E0 using different
locales:" << endl;
double a = 1234.56E0;
for (int i=0; i < sizeof(arrLocaleNames)/sizeof(arrLocaleNames[0]);
i++) {
poStrStream->imbue(locale( arrLocaleNames[i] ) );
*poStrStream << a << " <- locale(\"" << arrLocaleNames[i] << "\")
getloc().name():\"" <<
poStrStream- >getloc().name().c_str() << "\"" << endl;
}
// ----------------------------------------

cout << poStrStream->str();
delete poStrStream;

int k;
cin >> k;
return 0;
}

leads to the correct output:

output of double a=1234.56E0 using different locales:
1.234,56 <- locale("German_germany")
getloc().name():"German_Germany.1252"
1.234,56 <- locale("german-austrian")
getloc().name():"German_Austria.1252"
1'234.56 <- locale("german-swiss")
getloc().name():"German_Switzerland.1252"
1.234,56 <- locale("german-austrian")
getloc().name():"German_Austria.1252"
1234.56 <- locale("C") getloc().name():"C"
1á234,56 <- locale("French") getloc().name():"French_France.1252"
1.234,56 <- locale("") getloc().name():"German_Germany.1252"

But compiling the code between the two comment lines in a WinForms-project
as it is created by the VC2005-IDE using the same header files and namespace
std statement as above, results in the following output:

output of double a=1234.56E0 using different locales:
1234.56 <- locale("German_germany") getloc().name():"German_Germany.1252"
1234.56 <- locale("german-austrian") getloc().name():"German_Austria.1252"
1234.56 <- locale("german-swiss")
getloc().name():"German_Switzerland.1252"
1234.56 <- locale("german-austrian") getloc().name():"German_Austria.1252"
1234.56 <- locale("C") getloc().name():"C"
1234.56 <- locale("French") getloc().name():"French_France.1252"
1234.56 <- locale("") getloc().name():"German_Germany.1252"

Obviously the locale function produces the same output as in the console
version but the stream output stays with the standard "C" settings!

What do I have to change (compiler settings, move the piece of code out of
the click-handler of the WinForm) to get the correct results?

Thanks for your help

Rainer


Reply With Quote
  #2  
Old   
Lee Jones [MSFT]
 
Posts: n/a

Default RE: C++ locale and .NET -> conversion error running in .NET-environmen - 10-23-2006 , 08:43 PM






Hello Rainer,

Yes, I've reproduced this and confirmed that it is a known problem with /clrure complilation.
Apparently, the numpunct <char> facet is being initialized from the "C" locale instead of the instantiated and imbued locale.

~Lee

Lee Jones [MSFT]
Developer Division, Globalization Team

This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
--------------------
Quote:
Thread-Topic: C++ locale and .NET -> conversion error running in .NET-environmen
thread-index: AcbHcnTAIYna3M26RomeqO5GWGVKYQ==
X-WBNR-Posting-Host: 84.58.52.194
From: =?Utf-8?B?UmFpbmVySw==?= <RainerK (AT) discussions (DOT) microsoft.com
Subject: C++ locale and .NET -> conversion error running in .NET-environmen
Date: Thu, 24 Aug 2006 04:43:02 -0700
Lines: 83
Message-ID: <8094ED92-D9CB-4112-A2D0-19C520AD7E3C (AT) microsoft (DOT) com
MIME-Version: 1.0
Content-Type: text/plain;
charset="Utf-8"
Content-Transfer-Encoding: 8bit
X-Newsreader: Microsoft CDO for Windows 2000
Content-Class: urn:content-classes:message
Importance: normal
Priority: normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.1830
Newsgroups: microsoft.public.dotnet.internationalization
Path: TK2MSFTNGXA01.phx.gbl
Xref: TK2MSFTNGXA01.phx.gbl microsoft.public.dotnet.internationalization:2466
NNTP-Posting-Host: TK2MSFTNGXA01.phx.gbl 10.40.2.250
X-Tomcat-NG: microsoft.public.dotnet.internationalization

Hi,

running the following code as an console application:

#include <locale
#include <iostream
#include <sstream
#include <tchar.h

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
// ----------------------------------------
const char* arrLocaleNames[] = {
"German_germany",
"german-austrian",
"german-swiss",
"german-austrian",
"C",
"French",
"",
};
ostringstream* poStrStream = new ostringstream;
*poStrStream << "output of double a=1234.56E0 using different
locales:" << endl;
double a = 1234.56E0;
for (int i=0; i < sizeof(arrLocaleNames)/sizeof(arrLocaleNames[0]);
i++) {
poStrStream->imbue(locale( arrLocaleNames[i] ) );
*poStrStream << a << " <- locale(\"" << arrLocaleNames[i] << "\")
getloc().name():\""
poStrStream- >getloc().name().c_str() << "\"" << endl;
}
// ----------------------------------------

cout << poStrStream->str();
delete poStrStream;

int k;
cin >> k;
return 0;
}

leads to the correct output:

output of double a=1234.56E0 using different locales:
1.234,56 <- locale("German_germany")
getloc().name():"German_Germany.1252"
1.234,56 <- locale("german-austrian")
getloc().name():"German_Austria.1252"
1'234.56 <- locale("german-swiss")
getloc().name():"German_Switzerland.1252"
1.234,56 <- locale("german-austrian")
getloc().name():"German_Austria.1252"
1234.56 <- locale("C") getloc().name():"C"
1á234,56 <- locale("French") getloc().name():"French_France.1252"
1.234,56 <- locale("") getloc().name():"German_Germany.1252"

But compiling the code between the two comment lines in a WinForms-project
as it is created by the VC2005-IDE using the same header files and namespace
std statement as above, results in the following output:

output of double a=1234.56E0 using different locales:
1234.56 <- locale("German_germany") getloc().name():"German_Germany.1252"
1234.56 <- locale("german-austrian") getloc().name():"German_Austria.1252"
1234.56 <- locale("german-swiss")
getloc().name():"German_Switzerland.1252"
1234.56 <- locale("german-austrian") getloc().name():"German_Austria.1252"
1234.56 <- locale("C") getloc().name():"C"
1234.56 <- locale("French") getloc().name():"French_France.1252"
1234.56 <- locale("") getloc().name():"German_Germany.1252"

Obviously the locale function produces the same output as in the console
version but the stream output stays with the standard "C" settings!

What do I have to change (compiler settings, move the piece of code out of
the click-handler of the WinForm) to get the correct results?

Thanks for your help

Rainer



--




Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.