Skip to main content
gamedev.net
🔒 Locked

C++ into HTML Format

Started by Bam2k1 3 replies 800+ views
Original Post
Bam2k1
Bam2k1
Ok well here what I am doing. Theres a program that displays the results as a self web page like. There are these files for a game I wish to read. And I want them to display them into a html style web page. With tables, and each table displays part of the data in the text file. What would I look up and how would I go about doing that. I really don't know how to explain it much better but i'll keep trying. Any help would be nice. Once again its a program its not a web page. I want the program to display my results as a web page though. [edited by - Bam2k1 on June 1, 2003 4:26:46 AM] [edited by - Bam2k1 on June 1, 2003 4:27:53 AM]
Zipster
Zipster
You output to a regular text file with the HTML code, and give it the *.htm or *.html extension.

So if you have a bunch of data you want to put into a table, maybe something like this:

ofstream page("WebPage.htm");

page << "<table><tr>" << endl;

for(int i = 0; i < numData; ++i)
{
page << "<td>";
page << Data[i];
page << "</td>";
}

page << "</tr></table>";

page.close();

Of course that''s a really oversimplified example, but following a similar procedure you can output the necessary codes mixed with the data you want to display.

And BTW, your "test" worked
demonrealms
demonrealms
You would have to make and html file like this:
ofstream file_01("Results.html");
file_01 << "<table border=0>" << endl
<< "<tr>" << endl
<< "<td valign=top align=left>" << endl
<< Dataname here... << endl
<< "</td>" << endl
<< "</tr>" << endl
<< "</table>" << endl;
file_01.close();

that''s how i''d go about doing it.
then if you wish to have a look up engine
you could use some &#106avascript in your code
and make some text boxes and search thier
required input. like this:
_____________
| Top score |
-------------
_______________
| Submit |
demonrealms
demonrealms
You could do somthing like this:
(Please don''t yell at me if there''s a better way to do this b/c I''m almost dead sure there
is)
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main(void)
{
string user = "User 1";
int score = 1000;
int score2 = 200;
int tscore = score + score2;
ofstream result( "Result.html" );
result << "<html>" << endl
<< "<head>" << endl
<< "<title>Title here.....</title>" << endl
<< "</head>" << endl
<< "<body>" << endl
<< "<h1 align=center>Results</h1>" << endl
<< "<hr>" << endl
<< "<h3>Your top score is below</h3>" << endl
<< "<table border=2>" << endl
<< "<tr>" << endl
<< "<th>User</th>" << endl
<< "<th>Score 1</th>" << endl //<th> stands for table header

<< "<th>Score 2</th>" << endl
<< "<th>Total score</th>" << endl
<< "</tr>" << endl
<< "<tr>" << endl
<< "<td valign=top align=left><h4>" << user << "</h4></td>" << endl
<< "<td valign=top align=left><h4>" << score << "</td>" << endl
<< "<td valign=top align=left>" << score2 << "</td>" << endl
<< "<td valign=top align=left>" << tscore << "</h4></td>" << endl
<< "</tr>" << endl
<< "</table>" << endl
<< "<hr>" << endl
<< "<form name=''search''>" << endl
<< "<input type=''text'' name=''s1''>" << endl
<< "<input type=''button'' value=''Submit Request'' name=''submit'' onClick=''searchf();''>" << endl
<< "</form>" << endl
<< "<script>" << endl
<< "function searchf() {" << endl
<< "if(document.search.s1.value==''usrs'') {" << endl
<< "location.href=''user.html'';" << endl
<< " }" << endl
<< "}" << endl
<< "</script>" << endl
<< "</body>" << endl
<< "</html>" << endl;
result.close();
return(0);
}
Hope that helped. -_-

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.