fork(2) download
  1. #include <iostream>
  2. #include <sstream>
  3.  
  4. using namespace std;
  5.  
  6. struct chlit
  7. {
  8. chlit(char c) : c_(c) { }
  9. friend std::istream& operator>>(std::istream& is, chlit x)
  10. {
  11. char c;
  12. if (is >> c && c != x.c_)
  13. is.setstate(std::iostream::failbit);
  14. return is;
  15. }
  16. char c_;
  17. };
  18.  
  19. int main()
  20. {
  21. std::istringstream iss("(12, -34.78)");
  22. int a; double b;
  23. if (iss >> chlit('(') >> a >> chlit(',') >> b >> chlit(')'))
  24. std::cout << " a=" << a << " b=" << b << '\n';
  25. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
 a=12 b=-34.78