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
Asked
Active
Viewed 2.4k times
8
-
It could help if you explain what kind of report you want to create? Of data input to the program? Of the program itself? Something else? Also, should it be called from a web-server, or just generate pure HTML? – Some programmer dude Jun 26 '12 at 11:47
-
@JoachimPileborg I need to create report of the data that is calculated in inside the program, Input data is not to be included. Nothing is called from the web server, everything is called from the program itself. – vin Jun 26 '12 at 12:28
-
You could use a html template engine like [amber][1] [1]: http://stackoverflow.com/a/30281734/2261889 – burner Jul 07 '15 at 14:46
3 Answers
2
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

Drkawashima
- 8,837
- 5
- 41
- 52
-
Can you elaborate it a bit more? it gives an error that reads as: 'name followed by :: must be a class or a namespace name' – vin Jun 27 '12 at 06:08
-
Ah, I forgot that the StreamWriter and the System namespace isn't avaliable unless you use .Net CLR. I've updated the code so that it uses the ofstream class instead. The example content I've written creates one paragraph for each item in the reportData array. (Not that I haven't defined the array though, so it's just an example, the code isn't executable yet) – Drkawashima Jul 02 '12 at 15:28
0
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.

Nikolai Fetissov
- 82,306
- 11
- 110
- 171