Attached a small example taken from Bruce Eckel Thinking in C++

On cygwin both this call

  cout.imbue(locale("en_US.UTF-8"));

  cout.imbue(locale("fr_FR.UTF-8"));

raise exception

"terminate called after throwing an instance of 'std::runtime_error'
  what():  locale::facet::_S_create_c_locale name not valid
Aborted (core dumped)"

I could understand eventually the second one, but "English (US)" is the current windows locale so I expected that at least "en_US.UTF-8" is accepted.

What I am missing ?

Regards
Marco
//: C04:Locale.cpp {-g++}{-bor}{-edg} {RunByHand}
// Illustrates effects of locales.
#include <iostream>
#include <locale>
using namespace std;
 
int main() {
  locale def;
  cout << def.name() << endl;
  locale current = cout.getloc();
  cout << current.name() << endl;
  float val = 1234.56;
  cout << val << endl;

  // Change to US
  cout.imbue(locale("en_US.UTF-8"));
  current = cout.getloc();
  cout << current.name() << endl;
  cout << val << endl;

  // Change to French/France
  cout.imbue(locale("fr_FR.UTF-8"));
  current = cout.getloc();
  cout << current.name() << endl;
  cout << val << endl;

 
  cout << "Enter the literal 7890,12: ";
  cin.imbue(cout.getloc());
  cin >> val;
  cout << val << endl;
  cout.imbue(def);
  cout << val << endl;
} ///:~


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

Reply via email to