Locale

S

scuro

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.
 
R

Rolf Magnus

scuro said:
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++.
 
O

osmium

Rolf Magnus said:
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?
 
R

Rolf Magnus

osmium said:
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.
 
S

scuro

Rolf said:
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.
 
M

Marcus Kwok

scuro said:
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
 
O

osmium

:

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?
 
A

Alex Buell

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?
 
S

shaun roe

scuro said:
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.name()<<endl;
return 0;
}

a typical answer is

"C"

which tells you that a classic US English ASCII locale is used.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,196
Latest member
ScottChare

Latest Threads

Top