GIDForums  

Go Back   GIDForums > Computer Programming Forums > MS Visual C++ / MFC Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 17-Jun-2006, 13:16
dstrain dstrain is offline
New Member
 
Join Date: Jun 2006
Posts: 1
dstrain is on a distinguished road
Question

How can I take user input & insert into an existing and separate html page?


I'm new to programming and C++ and trying to build a basic webpage generator that takes user input from the command console and outputs it to a formatted html file.

So far I can accomplish the task with the following code, but its cumbersome and mixes the html code with the C++ code in the .cpp file:

CPP / C++ / C Code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main()
{
	
	ofstream outPage;
	outPage.open("webgenpage1.html");
	string pageTitle, pageContent;

	//Here the user is instructed to input the page title.

	cout << "The text you enter here will be the title of your webpage:" << endl;
	getline(cin, pageTitle);
	
	//Here the user is told what to enter for the main body of the page

	cout << "The text you enter here will be the content of the body of your webpage:" << endl;
	getline(cin, pageContent);

	//Here the html page's header output is created with the user's page title inserted

	outPage << "<html><head><title>" << pageTitle << "</title></head>" << endl;
	
	//Here the main content area is created with the user's input inserted

	outPage << "<table align='top'><tr><td valign='top'><font face='verdana' size='2'>" << pageContent << "</td></tr></table></table></body></html>" << endl;

	return 0;

}


Instead of the above way, I'd really like to be able to:

1. Format all of the html markup in a separate html file and use some sort of place-holder within the markup tags to represent user input (ex. <td>^page content^</td>) then....

2. ...within the .cpp file have just C++ code that opens and searches the existing html template file, finds the place-holders, replaces them with the user input, then saves the edited file in a new directory to be uploaded to a server?

I'd like to avoid having all the html mixed in with the C++ code. Any help is greatly appreciated!
Last edited by LuciWiz : 17-Jun-2006 at 16:21. Reason: Please insert your C++ code between [c++] & [/c++] tags
  #2  
Old 18-Jun-2006, 12:44
aie0 aie0 is offline
Member
 
Join Date: Dec 2004
Posts: 246
aie0 is a jewel in the roughaie0 is a jewel in the rough

Re: How can I take user input & insert into an existing and separate html page?


You could create a class ( htmlmaker) which will have methods like
addHead,addBody and things like that. It will be very helpful for you to look at the methods of java SOAPFactory class to see the direction of my thought.
 
 

Recent GIDBlogProgramming ebook direct download available by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 16:34.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.