#include <iostream>
#include <sstream>
#include <vector>
#include <string>
std::vector<std::string> extract_tag(std::istream& is, std::string tag_name)
{
std::vector<std::string> body_tokens;
std::string token;
while (is >> token && token != ('<' + tag_name + '>'))
;
while (is >> token && token != ("</" + tag_name + '>'))
body_tokens.push_back(token);
return body_tokens;
}
template <typename container_type>
void display(std::ostream& os, const container_type& container)
{
for (auto& element : container)
os << element << '\n';
}
std::string text =
R"(<html>
<body>
This is a test message.
</body>
</html>)";
int main()
{
std::istringstream in_stream(text);
display(std::cout, extract_tag(in_stream, "body"));
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3N0cmVhbT4KI2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPHN0cmluZz4KCgoKc3RkOjp2ZWN0b3I8c3RkOjpzdHJpbmc+IGV4dHJhY3RfdGFnKHN0ZDo6aXN0cmVhbSYgaXMsIHN0ZDo6c3RyaW5nIHRhZ19uYW1lKQp7CiAgICBzdGQ6OnZlY3RvcjxzdGQ6OnN0cmluZz4gYm9keV90b2tlbnM7CgogICAgc3RkOjpzdHJpbmcgdG9rZW47CgogICAgd2hpbGUgKGlzID4+IHRva2VuICYmIHRva2VuICE9ICgnPCcgKyB0YWdfbmFtZSArICc+JykpCiAgICAgICAgOwoKICAgIHdoaWxlIChpcyA+PiB0b2tlbiAmJiB0b2tlbiAhPSAoIjwvIiArIHRhZ19uYW1lICsgJz4nKSkKICAgICAgICBib2R5X3Rva2Vucy5wdXNoX2JhY2sodG9rZW4pOwoKICAgIHJldHVybiBib2R5X3Rva2VuczsKfQoKdGVtcGxhdGUgPHR5cGVuYW1lIGNvbnRhaW5lcl90eXBlPgp2b2lkIGRpc3BsYXkoc3RkOjpvc3RyZWFtJiBvcywgY29uc3QgY29udGFpbmVyX3R5cGUmIGNvbnRhaW5lcikKewogICAgZm9yIChhdXRvJiBlbGVtZW50IDogY29udGFpbmVyKQogICAgICAgIG9zIDw8IGVsZW1lbnQgPDwgJ1xuJz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