c++ read basic html page

hi, im trying to make a simple c++ program that will read some text in the html page.

here is the source of the html i want to read.

1
2
3
4
5
<html>
   <body>
      This is a test message.
   </body>
</html>


My expected result in c++ in an string array like this:

1
2
3
4
5
This
is
a
test
message


I tried to look around and I came across a function called InternetReadFile but I can't find any example similar to what I want. Thanks


You're looking at a somewhat complicated problem. To understand it you'd have to understand parsing lexing and tokenizing. Sorry I can't be of much help.
Here's a rather naive implementation:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#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"));
}


http://ideone.com/LgV1wD
@cire

what i means is that the program will go to the website (eg. test.com). My question is how can I get the data from that website.
> how can I get the data from that website.

libcurl is widely used, robust and non-viral. http://curl.haxx.se/libcurl/
Example: http://curl.haxx.se/libcurl/c/sepheaders.html
@JlBorges

thanks for the info, but im trying to avoid curl or curlpp for some reasons. im planning on using InternetReadFile but I can't find any good example regarding to my problem.
@JLBorge

thanks for the example, but it is for getting file. I will just search for more.
Topic archived. No new replies allowed.