fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <sstream>
  4.  
  5. std::string between(const std::string& haystack, const std::string& begin, const std::string& end)
  6. {
  7. size_t spos= haystack.find(begin);
  8. if (spos == std::string::npos) return "";
  9. size_t epos = haystack.find(end, spos+1);
  10. if (epos == std::string::npos) return "";
  11. return haystack.substr(spos+begin.size(), epos-spos-begin.size());
  12. }
  13.  
  14. int main()
  15. {
  16. std::string mystring;
  17. std::cin >> mystring;
  18. std::stringstream sstream(between(mystring, "<", ">"));
  19.  
  20. int myid;
  21. if (sstream >> myid)
  22. std::cout << mystring << " " << myid << std::endl;
  23. else
  24. std::cout << "error" << std::endl;
  25. }
Success #stdin #stdout 0.01s 2864KB
stdin
MYTAG<1>
stdout
MYTAG<1> 1