473,695 Members | 2,393 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(arrLocal eNames)/sizeof(arrLocal eNames[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_German y.1252"
1.234,56 <- locale("german-austrian")
getloc().name() :"German_Austri a.1252"
1'234.56 <- locale("german-swiss")
getloc().name() :"German_Switze rland.1252"
1.234,56 <- locale("german-austrian")
getloc().name() :"German_Austri a.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_German y.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_German y.1252"
1234.56 <- locale("german-austrian") getloc().name() :"German_Austri a.1252"
1234.56 <- locale("german-swiss")
getloc().name() :"German_Switze rland.1252"
1234.56 <- locale("german-austrian") getloc().name() :"German_Austri a.1252"
1234.56 <- locale("C") getloc().name() :"C"
1234.56 <- locale("French" ) getloc().name() :"French_France .1252"
1234.56 <- locale("") getloc().name() :"German_German y.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 1181

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

Similar topics

2
2881
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' >>> # Okay, we *are* in France now >>> locale.localeconv()
2
3329
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
3249
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 "license" for more information. >>> import locale >>> locale.setlocale(locale.LC_ALL, 'nl_NL')
2
1958
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, accented characters. I don't quite understand how the locale module reasons about these things, and Python doesn't seem to act as other programs on my system. Bug or my mistake? Here's my environment: frailea> env |grep -e LC -e LANG
10
2161
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 locales, even between unix's it's horrid.
1
2001
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 the standard conformant way of formatting and parsing locale specific date, time, strings with various character encoding, etc. Thanks
3
2404
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 be used for the excerpts. This means that I have to wrap calls to gettext() in a function that sets the locale temporarily. The problem is how to do that. Let's assume I need to generate German snippets. Then I could say
10
2283
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 following files in order (assuming I am running from the us): help\datasource_en_US.htm help\datasource_en.htm help\datasource.htm
3
7193
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 "<interactive input>", line 1, in <module> File "C:\Python25\lib\locale.py", line 476, in setlocale return _setlocale(category, locale) Error: unsupported locale setting
24
3373
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 without 'utf8' in it, then things start to go downhill: 2a. The app assumes unicode objects internally. i.e. Whenever there is
0
8578
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9120
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8998
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8831
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6494
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5841
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4346
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3013
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
1979
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.