fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <sstream>
  4.  
  5. struct A
  6. {
  7. std::string text;
  8. };
  9.  
  10. std::istream& operator>>(std::istream& is, A& a)
  11. {
  12. return is >> a.text;
  13. }
  14.  
  15. int f(std::string const &s)
  16. {
  17. A a;
  18. int b;
  19. if (std::istringstream{ s } >> a >> b)
  20. {
  21. return std::stoi(a.text) + b;
  22. }
  23. return 0;
  24. }
  25.  
  26. int main()
  27. {
  28. std::cout << f("1 2") << std::endl;
  29. }
Success #stdin #stdout 0s 3476KB
stdin
Standard input is empty
stdout
3