fork download
  1. #include <iostream>
  2. #include <sstream>
  3. #include <vector>
  4. #include <string>
  5.  
  6.  
  7.  
  8. std::vector<std::string> extract_tag(std::istream& is, std::string tag_name)
  9. {
  10. std::vector<std::string> body_tokens;
  11.  
  12. std::string token;
  13.  
  14. while (is >> token && token != ('<' + tag_name + '>'))
  15. ;
  16.  
  17. while (is >> token && token != ("</" + tag_name + '>'))
  18. body_tokens.push_back(token);
  19.  
  20. return body_tokens;
  21. }
  22.  
  23. template <typename container_type>
  24. void display(std::ostream& os, const container_type& container)
  25. {
  26. for (auto& element : container)
  27. os << element << '\n';
  28. }
  29.  
  30. std::string text =
  31. R"(<html>
  32. <body>
  33. This is a test message.
  34. </body>
  35. </html>)";
  36.  
  37.  
  38. int main()
  39. {
  40. std::istringstream in_stream(text);
  41. display(std::cout, extract_tag(in_stream, "body"));
  42. }
Success #stdin #stdout 0s 3432KB
stdin
Standard input is empty
stdout
This
is
a
test
message.