vin
vin

Reputation: 869

Create HTML reports using C++

Well, I have finished coding and all my results are ready, all I need to do now is create HTML reports to display these results. How do I create HTML report using C++? any Idea? If it helps, I am using Visual Studio to compile and run my code, although I am not very keen on using VS libraries and I would prefer using C++ std libraries, if there are any. Thank you in advance

Upvotes: 8

Views: 26392

Answers (3)

Sadık
Sadık

Reputation: 4419

What you might want here is a C++ HTML Template Engine. You can find a list here

Upvotes: 0

Drkawashima
Drkawashima

Reputation: 9762

A quick way to do it is simply writing the html tags as strings. Here's an example

    ofstream myfile;
    myfile.open ("C:\\report.html");
    myfile << "<!DOCTYPE html><html><head></head><body>"; //starting html

    //add some html content
    //as an example: if you have array of objects featuring the properties name & value, you can print out a new line for each property pairs like this:
    for (int i=0; i< reportData.length(); i++)
        myfile << "<p><span style='font-weight: bold'>" << reportData[i].name << "</span><span>" << reportData[i].value << "</span></p>";

   //ending html
    myfile << "</body></html>";
    myfile.close();

Edit: updated code

Upvotes: 2

Nikolai Fetissov
Nikolai Fetissov

Reputation: 84159

Well, HTML is text, so all regular tools from write to std::ostream are totally able to produce output for you. I would suggest though that you just generate XML describing you data structure hierarchy and then apply scripts, style sheets, or whatnot to format it to you liking.

Upvotes: 0

Related Questions