473,394 Members | 1,878 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

C++ locale and .NET -> conversion error using .NET

Hi all,

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
Aug 22 '06 #1
0 1158

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jeff Epler | last post by:
I'd expect these two to be identical, but they don't seem to be. >>> import locale >>> locale.setlocale(locale.LC_ALL, "fr_FR") 'fr_FR' >>> locale.nl_langinfo(locale.DAY_1) 'dimanche' >>> #...
2
by: Benoît Dejean | last post by:
here are my locales benoit@athlon >> locale LANG=fr_FR.UTF-8 LC_CTYPE="fr_FR.UTF-8" LC_NUMERIC="fr_FR.UTF-8" LC_TIME="fr_FR.UTF-8" LC_COLLATE="fr_FR.UTF-8" LC_MONETARY="fr_FR.UTF-8"
3
by: Ksenia Marasanova | last post by:
Hi, I have some problems with locale module. On my workstation, changing locale doesn't have effect: Python 2.3 (#1, Sep 13 2003, 00:49:11) on darwin Type "help", "copyright", "credits" or...
2
by: Jorgen Grahn | last post by:
I'm sitting here with a Debian Linux 'Woody' system with the default Python 2.2 installation, and I want the re module to understand that re.compile(r'\W+'. re.LOCALE) doesn't match my national,...
10
by: Timothy Smith | last post by:
hi there i need to set my locale so that when i output a number it's formatted with thousands grouped. the problem i've found is there doesn't seem to be very good cross platform support for...
1
by: Cagdas Ozgenc | last post by:
Greetings. I am confused about C++ standard library locale stuff. It seems as if the implementations of locales are not part of the library, but only some guideline classes are there. What is...
3
by: Torsten Bronger | last post by:
Hallöchen! I have to generate excerpts in different human languages in a program. In general, the language is not the locale's language, but set at runtime. Nevertheless, GNU's gettext should...
10
by: David Thielen | last post by:
Hi; I have help html pages for each page of my ASP.NET webapp. So for the page datasource.aspx, I have help\datasource.htm. Bu what I want when the hyperlink is clicked, for it to look for the...
3
by: robert | last post by:
Why can the default locale not be set by its true name? but only by '' ? : PythonWin 2.5 (r25:51908, Sep 19 2006, 09:52:17) on win32. (None, None) Traceback (most recent call last): File...
24
by: Donn Ingle | last post by:
Hello, I hope someone can illuminate this situation for me. Here's the nutshell: 1. On start I call locale.setlocale(locale.LC_ALL,''), the getlocale. 2. If this returns "C" or anything...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.