Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Imbue



Permlink Replies: 1 - Last Post: Jan 23, 2018 12:01 PM Last Post By: Remy Lebeau (Te... Threads: [ Previous | Next ]
John David

Posts: 86
Registered: 9/5/16
Imbue
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 23, 2018 10:10 AM
I have just noticed that none of the Embarcadero products support imbue
locale. For example, the simple program pasted here should display
(British/US locale; Germans, France will have their own formats):

1,000,000

but it prints:

1000000

<+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>

// imbue example
#include <iostream> // std::cout
#include <locale> // std::locale

using namespace std;

int main()
{
locale mylocale(""); // get global locale
cout.imbue(mylocale); // imbue global locale
cout << 1000000 << endl;
return 0;
}


<+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>

All Visual Studio versions since 2010 can compile correctly and give
correct results. Any ideas where this should be reported so that the
developers can fix it in the next update? Probably they don't know
about this because nobody uses it in practical daily life.

Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Imbue
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 23, 2018 12:01 PM   in response to: John David in response to: John David
John David wrote:

I have just noticed that none of the Embarcadero products support
imbue locale. For example, the simple program pasted here should
display (British/US locale; Germans, France will have their own
formats):

1,000,000

but it prints:

1000000

You are imbue'ing a default locale, which is compiler-dependant and
based on the user's environment. That does not guarantee that
separators are defined or used in formatting operations.

You need to use an explicitly named locale that does define separators.

Or, you can derive your own locale punctuation to use whatever
separators you want (such as the global ThousandSeparator and
DecimalSeparator from C++Builder's RTL):

https://stackoverflow.com/a/17530535/65863

--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02