error - locale name not valid

The following example is excerpted from Stroustrup's book:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/// ...

void test(istream& fin, ostream& fout,
          istream& fin2, ostream& fout2)
{
   fin.imbue(locale {"en_US.UTF-8"});	/// American English
   fout.imbue(locale {"fr_FR.UTF-8"});	/// French

   /// read American English, write French
   copy(fin, fout);

   /// ...

   fin2.imbue(locale {"fr_FR.UTF-8"});	/// French
   fout2.imbue(locale {"en_US.UTF-8"});	/// American English

   /// read French, write American English
   copy(fin2, fout2);
}

/// ... 


https://ideone.com/zuJEcq


However, I get the following compilation error:


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


Please advise how to proceed in this case. Thanks.
Locale names are implementation specific.

In particular, with the GNU library on non-Linux systems, do not rely on anything more than token support for locales: ie. the classic locale ("C"), the posix locale ("POSIX") and the default locale ("").

Ideally, on Windows, either use the Microsoft implementation or use Boost.Locale in conjunction with ICU.
Topic archived. No new replies allowed.