fork download
  1. #include <locale>
  2. #include <iostream>
  3. #include <sstream>
  4. #include <iomanip>
  5.  
  6. struct skip_extra : std::ctype<char> {
  7. skip_extra()
  8. : std::ctype<char>( get_table() )
  9. {}
  10. static const mask* get_table() {
  11. static const std::array<mask, table_size> table = [&]() {
  12. std::array<mask, table_size> table;
  13. std::copy( classic_table(), classic_table() + table_size, table.begin() );
  14. table['"'] |= space;
  15. table['\''] |= space;
  16. table['['] |= space;
  17. table[']'] |= space;
  18. table[','] |= space;
  19. return table;
  20. }();
  21. return table.begin();
  22. }
  23. };
  24.  
  25. int main() {
  26. std::istringstream s( "\"[['1.81592098644987','52.5487429714954'],['-1.81592290792183','52.5487234624632']]\"" );
  27. s.imbue( std::locale( s.getloc(), new skip_extra ) );
  28. double x;
  29. while ( s >> x ) {
  30. std::cout << std::setprecision( 15 ) << x << "\n";
  31. }
  32. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
1.81592098644987
52.5487429714954
-1.81592290792183
52.5487234624632