473,473 Members | 1,894 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Create C++ std::locale without changing C locale

Hello newsgroup,

is it possible to create a std::locale object without changing the
global C locale? Is this implementation defined?

My problem is that I work in a multi-threaded environment that has to
deal with two different locales. Unfortunately, the code uses plain C
functions for IO at many places. However, there is a single point that
uses std::isprint with a C++ locale that is different from the
standard locale. That's why I'm interested in quick and dirty solution
to construct a C++ locale without changing the global C locale.

I've found two other possible work-arounds: (A) printf_l. I don't know
whether this is part of the C standard but nevertheless my IO library
doesn't contain it. (B) A Microsoft Visual C specific solution using a
function called _configthreadlocale which is also not part of my IO
library (there is no information available when this function was
added to Visual C).

Any suggestions (even if they are just "replace all C calls by
iostream calls") are highly welcome.

TIA,
Stuart
Aug 26 '08 #1
4 3347
Sam
de*******@web.de writes:
Hello newsgroup,

is it possible to create a std::locale object without changing the
global C locale? Is this implementation defined?
Although I haven't checked, I'd be surprised if merely instantiating a
std::locale object changes the global C locale.

I would expect that the global C locale would only be affected by
std::locale::global().
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEABECAAYFAkiz5F4ACgkQx9p3GYHlUOJcBQCggS+GfPC+gC AWjNOfQWAkYla5
+B0An1TjVwyaeIq5cbvSVXaU+6MmNVgK
=oekt
-----END PGP SIGNATURE-----

Aug 26 '08 #2
On 26 Aug., 13:09, Sam <s...@email-scan.comwrote:
dertop...@web.de writes:
Hello newsgroup,
is it possible to create a std::locale object without changing the
global C locale? Is this implementation defined?

Although I haven't checked, I'd be surprised if merely instantiating a
std::locale object changes the global C locale.

I would expect that the global C locale would only be affected by
std::locale::global().
Yes, I thought so, too. The following programme taught me else.

#include <xlocale>
int main(int argc, char* argv[])
{
printf ("%f\n", 3.14);
std::locale loc ("German_Germany");
printf ("%f", 3.14);
}

Output:3.140000
3,140000

Is my implementation of the Standard Library (Visual C 6.0) faulty,
then?

Stuart
Aug 26 '08 #3
In article <c66cd8b9-2503-4579-894d-
48**********@z11g2000prl.googlegroups.com>, de*******@web.de says...

[ ... ]
#include <xlocale>
int main(int argc, char* argv[])
{
printf ("%f\n", 3.14);
std::locale loc ("German_Germany");
printf ("%f", 3.14);
}

Output:3.140000
3,140000

Is my implementation of the Standard Library (Visual C 6.0) faulty,
then?
Yes. Your code isn't entirely correct either, but fixing the code
doesn't make any difference with VC 6. Here's the corrected code:

#include <locale>

int main(int argc, char* argv[])
{
printf ("%f\n", 3.14);
std::locale loc ("German_Germany");
printf ("%f", 3.14);
}

The output with VC 6 is the same as you showed, but with VC 7 (or newer)
or almost any other recent compiler, the output is like this:

3.140000
3.140000

--
Later,
Jerry.

The universe is a figment of its own imagination.
Aug 26 '08 #4
On 26 Aug., 15:08, Jerry Coffin <jcof...@taeus.comwrote:
In article <c66cd8b9-2503-4579-894d-
484a385ba...@z11g2000prl.googlegroups.com>, dertop...@web.de says...

[ ... ]
#include <xlocale>
int main(int argc, char* argv[])
{
* printf ("%f\n", 3.14);
* std::locale loc ("German_Germany");
* printf ("%f", 3.14);
}
Output:3.140000
3,140000
Is my implementation of the Standard Library (Visual C 6.0) faulty,
then?

Yes. Your code isn't entirely correct either, but fixing the code
doesn't make any difference with VC 6. Here's the corrected code:

#include <locale>

int main(int argc, char* argv[])
{
* printf ("%f\n", 3.14);
* std::locale loc ("German_Germany");
* printf ("%f", 3.14);

}

The output with VC 6 is the same as you showed, but with VC 7 (or newer)
or almost any other recent compiler, the output is like this:

3.140000
3.140000
Thanks.
Aug 26 '08 #5

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

Similar topics

4
by: Roger Leigh | last post by:
Hello, I'm writing a fixed-precision floating point class, based on the ideas in the example fixed_pt class in the "Practical C++ Programming" book by Steve Oualline (O' Reilly). This uses a...
0
by: Craig Cookesley | last post by:
Hi I have written an application using Delphi 6 and Interbase 7 basically it use external tables to read and write an external file (basic text file) My problem is strange and I can not...
0
by: jalkadir | last post by:
When compiling this progra, I get an error that reads: *** Compiler : GNU GCC Compiler (called directly) --------------------------------------------------------------------------------...
6
by: Nemok | last post by:
Hi, I am new to STD so I have some questions about std::string because I want use it in one of my projects instead of CString. 1. Is memory set dinamicaly (like CString), can I define for...
7
by: Peter Jansson | last post by:
Dear group, I have been struggling to get a simple program for inserting and extracting std::tm objects to/from streams to work. The code below tries to read a std::tm object from a...
2
by: cris | last post by:
Hi, I got trouble when I try to change the locale used in a program foo.cc // ----------------- begin #include <iostream> #include <locale> #include <exception> using namespace std; int...
2
by: year1943 | last post by:
There was the same topic not so long ago, but as I see it stays w/o answer:...
5
by: Sashi Asokarajan | last post by:
Hello, recently I stepped over Strotrup's TC++PL (third ed.) Chapter D.1 where the localization support of the C++ stdlib is explained. http://www.research.att.com/~bs/3rd_loc.pdf ] ...
5
by: Noah Roberts | last post by:
A lot of my code converts numeric values to strings using boost::lexical_cast, and thus, underneath, with <<. When I activate locales, the thousands separator turns on. We've deemed it not...
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,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
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...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.