473,395 Members | 1,457 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,395 software developers and data experts.

Dinkumware STL using Local

I use Dinkumware's STL with Borland C++ Builder 2006 (part of BDS
2006) to convert from a character array to a double in a Windows
application. This approach works well for English, but fails for
French as "0,1" (note the comma) is not interpreted as a decimal
point. What can I do to get setlocale() or Window's French regional
setting to work? Thanks. -Ken

#include <strstream>
double d;

setlocale(LC_ALL, "C");
SMove( d, "0.1"); // decimal point is a period. result: d = 0.1

setlocale(LC_ALL, "french");
SMove( d, "0,1"); // decimal point is a comma. result: d = 0

void SMove( double& dVal, char *sStr, int nLen )
{
istrstream s( sStr, nLen );
s >dVal;
}

Jul 16 '07 #1
3 3072
kenwilkinson wrote:
I use Dinkumware's STL with Borland C++ Builder 2006 (part of BDS
2006) to convert from a character array to a double in a Windows
application. This approach works well for English, but fails for
French as "0,1" (note the comma) is not interpreted as a decimal
point. What can I do to get setlocale() or Window's French regional
setting to work?
I don't know. This prints
0.1
0.1
on my computer though.

#include <strstream>
#include <locale>
#include <iostream>

void SMove( double& dVal, char *sStr, int nLen )
{
std::istrstream s( sStr, nLen );
s >dVal;
}

int main()
{
double d;

std::locale::global(std::locale("C"));
SMove( d, "0.1", 3); // decimal point is a period. result: d = 0.1
std::cout << d << '\n';

std::locale::global(std::locale("fr_FR"));
SMove( d, "0,1", 3); // decimal point is a comma. result: d = 0
std::cout << d << '\n';
}
#include <strstream>
double d;

setlocale(LC_ALL, "C");
SMove( d, "0.1"); // decimal point is a period. result: d = 0.1

setlocale(LC_ALL, "french");
SMove( d, "0,1"); // decimal point is a comma. result: d = 0

void SMove( double& dVal, char *sStr, int nLen )
{
istrstream s( sStr, nLen );
s >dVal;
}
I suggest you 1) provide compilable examples, and 2) read appendix D from
The C++ Programming Language, available from
<URL:http://www.research.att.com/~bs/3rd_loc0.html>.

--
rbh
Jul 16 '07 #2
Thanks, Robert. Your code worked perfectly. I'm unsure how to have
locale work properly from program startup. From what I read, the STL
should pickup the locale on its own, prior to main(). -ken

Jul 16 '07 #3
kenwilkinson wrote:
Thanks, Robert. Your code worked perfectly. I'm unsure how to have
locale work properly from program startup. From what I read, the STL
should pickup the locale on its own, prior to main().
The program will start up with the C locale. To get the user defined locale,
you can do:

std::locale loc(""); //user's preferred locale
// Set user's preferred locale as default for new streams.
std::locale::global(loc);

//make cin, cout ... use this
std::cin.imbue(loc);
std::cout.imbue(loc);
std::cerr.imbue(loc);
std::clog.imbue(loc);

Btw. 'STL' usually refers to other parts of the standard library than the
locale and streams libraries.

--
rbh
Jul 16 '07 #4

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

Similar topics

0
by: Adam | last post by:
I have an application which interacts with a webserver over https using client certificates. Due to a bug in openssl 0.9.6, I upgraded to 0.9.7 and rebuilt python. Now, when I access the page...
7
by: Bob Hairgrove | last post by:
Hi, The Digital Mars compiler is not listed on the Dinkumware library's compatibility list on their web site. I would like to use the Dinkumware STL (source code license) together with the...
13
by: david | last post by:
Hi, I have some problems to link a simple hello world program using g++ (version 3.2.3 or 3.3) and dinkumware 402. //hallo world... #include <iostream> main () { std::cout << "bla" <<...
5
by: blugus | last post by:
Hi Guys, I've been try to use Dinkum STL library. It workes well first, but report memory leak in MFC Debug Mode. I use Dinkum Unabridged Library for VC++ V4.02, MSVC6, WIN2000 SERVER. I...
8
by: Sergio Otoya | last post by:
Hi all, I need to add an input hidden field to an existing form (post). I have tried a couple things like adding the '<INPUT type=hidden name=idSelectedURL value=http://server/documents>' to...
0
by: Richard Taylor | last post by:
User-Agent: OSXnews 2.07 Xref: number1.nntp.dca.giganews.com comp.lang.python:437315 Hi I am trying to use py2app (http://undefined.org/python/) to package a gnome-python application...
1
by: lecnac | last post by:
Sorry for the repost. I must have done something wrong when I tried to post my reply (I can't seem to find it). Anyway, I'd really appreciate any help that anyone could provide. My issue is...
1
by: jmalone | last post by:
I have a python script that I need to freeze on AIX 5.1 (customer has AIX and does not want to install Python). The python script is pretty simple (the only things it imports are sys and socket)....
0
by: Grant Edwards | last post by:
I've got a system where I try to install extensions using /usr/local/bin/python setup.py install But, it fails when it tries to use a non-existant compiler path and specs file. I suspect it's...
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
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
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...
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.