473,779 Members | 2,023 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Locale

Is there a way using standard C++ to obtain the machine locale? I need
to parse a date written in a text file, so i have to know first what is
the locale to be able to store correctly the date in a structure.

Thanks.
Jun 9 '06 #1
9 2287
scuro wrote:
Is there a way using standard C++ to obtain the machine locale? I need
to parse a date written in a text file, so i have to know first what is
the locale to be able to store correctly the date in a structure.


Why do you need to know the current locale? It's used by default in C++.

Jun 9 '06 #2
"Rolf Magnus" writes:
scuro wrote:
Is there a way using standard C++ to obtain the machine locale? I need
to parse a date written in a text file, so i have to know first what is
the locale to be able to store correctly the date in a structure.


Why do you need to know the current locale? It's used by default in C++.


Perhaps he has devised some fiendishly clever way to transport programs or
data from one location to another?
Jun 9 '06 #3
osmium wrote:
"Rolf Magnus" writes:
scuro wrote:
Is there a way using standard C++ to obtain the machine locale? I need
to parse a date written in a text file, so i have to know first what is
the locale to be able to store correctly the date in a structure.


Why do you need to know the current locale? It's used by default in C++.


Perhaps he has devised some fiendishly clever way to transport programs or
data from one location to another?


Then he wouldn't need the current system locale, but the one that the data
was encoded in.

Jun 9 '06 #4
Rolf Magnus a écrit :

Why do you need to know the current locale? It's used by default in C++.


Really?
I don't know what the standard says about this but, on the platform I'm
most familiar with (VC++ 7.1), the global locale is initially set to
the "classic" locale:
http://msdn2.microsoft.com/en-us/library/9dzxxx2c.aspx

To get the user's locale, one has to use std::locale("") ;

Éric

Jun 9 '06 #5
Rolf Magnus wrote:
Why do you need to know the current locale? It's used by default in C++.


Suppose you have a string like this one: "The party will be on 1/2/2000"
(this string was written into a file by a program on the same machine
where I run my program).

Now, the question is: if I want to go to the party I must go on 1
February 2000 or on 2 January 2000?

I have tho know the machine locale to correctly parse the date.
Jun 9 '06 #6
scuro <cr****@levami. lycos.com> wrote:
Suppose you have a string like this one: "The party will be on 1/2/2000"
(this string was written into a file by a program on the same machine
where I run my program).

Now, the question is: if I want to go to the party I must go on 1
February 2000 or on 2 January 2000?


This may not help you solve your locale problem, but in the future you
may want to consider using ISO 8601 date/time format, as it is
unambigous, plus you get the added bonus that a chronological sort and a
lexicographical sort are the same:

YYYY-MM-DD hh:mm:ss
http://www.cl.cam.ac.uk/~mgk25/iso-time.html

--
Marcus Kwok
Replace 'invalid' with 'net' to reply
Jun 9 '06 #7
"Marcus Kwok" writes:

Suppose you have a string like this one: "The party will be on 1/2/2000"
(this string was written into a file by a program on the same machine
where I run my program).

Now, the question is: if I want to go to the party I must go on 1
February 2000 or on 2 January 2000?


This may not help you solve your locale problem, but in the future you
may want to consider using ISO 8601 date/time format, as it is
unambigous, plus you get the added bonus that a chronological sort and a
lexicographical sort are the same:


Just a wild guess, but what if someone *else* wrote the message? ISTM if
the OP wrote the message, he would have a pretty good clue as to what it
meant. I sometimes receive mail on stationary I don't like, what is the
protocol for handling that?
Jun 9 '06 #8
On Fri, 09 Jun 2006 11:00:29 +0200, I waved a wand and this message
magically appeared from Rolf Magnus:
Is there a way using standard C++ to obtain the machine locale? I
need to parse a date written in a text file, so i have to know
first what is the locale to be able to store correctly the date in
a structure.


Why do you need to know the current locale? It's used by default in C+
+.


What he's trying to say is he needs to know what format the date is in
for that locale the system is running on.

For that matter, there really needs to be a way programs can find out
what country it is being used in. Is there a way like that?
--
http://www.munted.org.uk

Take a nap, it saves lives.
Jun 9 '06 #9
In article <44************ ********@news.t iscali.it>,
scuro <cr****@levami. lycos.com> wrote:
Is there a way using standard C++ to obtain the machine locale? I need
to parse a date written in a text file, so i have to know first what is
the locale to be able to store correctly the date in a structure.

Thanks.


#include <iostream>

using namespace std;
int main (int argc, char * const argv[]) {

locale native("");
cout<<native.na me()<<endl;
return 0;
}

a typical answer is

"C"

which tells you that a classic US English ASCII locale is used.
Jun 10 '06 #10

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

Similar topics

3
3260
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
1964
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
1
2007
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
0
1183
by: | last post by:
Hi all, running the following code as an console application: #include <locale> #include <iostream> #include <sstream> #include <tchar.h> using namespace std;
3
7203
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
2
11923
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 main(int argc, char** argv)
2
3643
by: Daniele C. | last post by:
I will report a snippet from http://php.net/setlocale I spent about 2 seconds before thinking: can it really be? I mean, is there no way to set locale info per thread? And after a brief web search I came up with this keyword: _configthreadlocale Read more at http://msdn2.microsoft.com/en-us/library//26c0tb7x(VS.80).aspx (beware, this page is very slow or their servers are anyway). Looks like this function exists since Windows 95 and...
24
3389
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
1535
by: Roman Bertle | last post by:
Hello, I try to format monetary values using the locale module, python2.5: Python 2.5.2a0 (r251:54863, Jan 3 2008, 17:59:56) on linux2 Type "help", "copyright", "credits" or "license" for more information. 'de_AT.utf8' {'mon_decimal_point': ',', 'int_frac_digits': 2, 'p_sep_by_space': 1, 'frac_digits': 2, 'thousands_sep': '', 'n_sign_posn': 1,
3
1624
by: Mario Ruggier | last post by:
Hi, i had the following problem when installing py3.0rc1 on a Mac OS X 10.5.5. On this system, the default locale values are: $ locale LANG= LC_COLLATE="C" LC_CTYPE="UTF-8" LC_MESSAGES="C"
0
9471
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
10302
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
10136
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...
1
10071
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9925
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
7478
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
5372
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
4036
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
2867
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.