fork download
  1. #include <istream>
  2. #include <ostream>
  3. #include <iostream> /// cout
  4. #include <sstream> /// istringstream
  5. #include <locale>
  6. #include <string>
  7.  
  8. using namespace std;
  9.  
  10.  
  11. /// Copy a pair of values from an istream to an ostream.
  12. void copy(istream& is, ostream& os)
  13. {
  14. float area;
  15. double volume;
  16.  
  17. while (is >> area >> volume)
  18. os << area << ' '
  19. << volume << '\n';
  20.  
  21. os << endl;
  22. }
  23.  
  24.  
  25. void test(istream& fin, ostream& fout,
  26. istream& fin2, ostream& fout2)
  27. {
  28. fin.imbue(locale {"en_US.UTF-8"}); /// American English
  29. fout.imbue(locale {"fr_FR.UTF-8"}); /// French
  30.  
  31. /// read American English, write French
  32. copy(fin, fout);
  33.  
  34. /// ...
  35.  
  36. fin2.imbue(locale {"fr_FR.UTF-8"}); /// French
  37. fout2.imbue(locale {"en_US.UTF-8"}); /// American English
  38.  
  39. /// read French, write American English
  40. copy(fin2, fout2);
  41. }
  42.  
  43.  
  44. int main()
  45. {
  46. /// American English
  47. string AmerEng {"100.3 1000.3 34.55 345.45 968.83 9688.321"};
  48. istringstream issAmerEng {AmerEng};
  49.  
  50. /// French
  51. string Frnch {"100,3 1000,3 34,55 345,45 968,83 9688,321"};
  52. istringstream issFrnch {Frnch};
  53.  
  54. test(issAmerEng, cout,
  55. issFrnch, cout);
  56. }
Runtime error #stdin #stdout #stderr 0s 16912KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
terminate called after throwing an instance of 'std::runtime_error'
  what():  locale::facet::_S_create_c_locale name not valid