![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
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 |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |