fork download
  1. #include <iostream>
  2. #include <sstream>
  3. #include <locale>
  4. #include <clocale>
  5. #include <stdlib.h>
  6.  
  7. template <class charT, charT sep>
  8. class punct_facet: public std::numpunct<charT> {
  9. protected:
  10. charT do_decimal_point() const { return sep; }
  11. };
  12.  
  13. int main() {
  14. auto lc = std::locale(std::locale("C"), new punct_facet<char, ','>);
  15. std::locale::global(lc);
  16. std::cout.imbue(lc);
  17.  
  18. std::stringstream str("2,134 43,54 22,334");
  19. double d;
  20. while (str >> d)
  21. {
  22. std::cout << d << '\n';
  23. }
  24. return 0;
  25. }
  26.  
Success #stdin #stdout 0.01s 5436KB
stdin
Standard input is empty
stdout
2,134
43,54
22,334