-
Outputting to html
I am currently working on some webpages through www.bravehost.com and I need some help on some stuff.
I am too lazy to make a crapload of html files on my computer and then upload them all to the server, so I am going to attempt to create them in my C++ IDE, which is Codeblocks.
I need to enter a number for the name of the file (i.e. 1 for 1.html, and 2 for 2.html, and so on) until I type a void number to exit the loop. I need to make around 30 files. The files need to contain:
Code:
<html>
<head>
<title>Redirection</title>
<meta http-equiv="refresh" content="0; url=http://guild.the-reincarnation.com/encyclopedia/spell/101.html">
</head>
<body bgcolor="black">
<h2 style="color:white">Redirecting</h2>
</body
</html>
The spell/101.html needs to be a variable, the one that I typed in, and each file needs to be saved under the same name. I do know a bit of C++, but I'm still kinda sketchy on a few things. I just barely got back into when I found out that I can use the using namespace std; function to use cin and cout functions.
I am not 100% sure on the loops or the output functions, but that's why I posted in here ;).
-
Well the beauty of HTML is that it's standard text, which means you can create and open them with ofstream. If you know file I/O, then this should be no problem, otherwise I could post an example.
Simply make a string, input whatever you want into it in the program, concatenate .html onto the end of the string the open the string. You've now created an HTML file which you can output code into.
Here is some example code:
Code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
ofstream makeHTML;
string pageName;
cout << "Enter the name you want for the webpage: ";
cin >> pageName; // I use cin rather than getline because you don't
// want spaces here.
pageName += ".html"; // Add .html to the end. You may want to do a check
// to see if the user already put it in.
makeHTML.open(pageName.c_str());
makeHTML << "<html> \n" << endl;
makeHTML << "<head> \n <title>HTML in C++ is easy!</title> \n </head> \n" << endl;
makeHTML << "<body> \n \n <p align=\"center\"><b><font size=\"5\">CONGRATULATIONS! ";
makeHTML << "YOU JUST MADE AN HTML PAGE IN C++!</font></b></p> \n" << endl;
makeHTML << "</body> \n </html>";
return 0;
}
-
Ok, that is great, but I have forgotten a lot of things so I need a link to some info. I can't remember much about sytaxing, but I can see the program in my head lol.
-
Have you tried the cprogramming tutorials? ;)
If you have a specific question, feel free to ask.
-
The URL for what I am doing is http://mistformshadow.bravehost.com/tcastatrep.html
if you scroll down and click on the "Spell Book" link, you will see a list of spells. The HTML says to move directories in the immediate one, like to /encyclopedia/spells/name.html. The spells are in a totally different site and I just copied and pasted the source. I am redirecting these by creating short files with code saying, "Redirecting" and it takes you to the site, which is what the HTML states above. The only variables are the name of the document (1.html) and the URL inside the codes.
-
Ok, here it is ;).
Code:
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ofstream makeHTML;
string pageName;
do {
cout << "Enter the page name:";
cin >> pageName;
if (pageName !="exit") {
pageName += ".html";
makeHTML.open(pageName.c_str());
makeHTML << "<html> \n" << endl;
makeHTML << "<head> \n" << endl;
makeHTML << "<title>Redirection</title> \n" << endl;
makeHTML << "<meta http-equiv=\"refresh\" content=\"0; url=http://guild.the-reincarnation.com/encyclopedia/spell/" << pageName << ".html\"> \n"<< endl;
makeHTML << "</head> \n" << endl;
makeHTML << "<body bgcolor=\"black\"> \n" << endl;
makeHTML << "<h2 stlye=\"color:white\">Redirecting</h2> \n" << endl;
makeHTML << "</body> \n" << endl;
makeHTML << "</html> \n" << endl;
makeHTML.close();
}
} while (pageName != "exit");
return 0;
}
-
Code:
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ofstream makeHTML;
string pageName;
do {
cout << "Enter the page name:";
cin >> pageName;
if (pageName != "exit") {
pageName += ".html";
makeHTML.open(pageName.c_str());
makeHTML << "<html> \n" << endl;
makeHTML << "<head> \n" << endl;
makeHTML << "<title>Redirection</title>" \n << endl;
makeHTML << "<meta http-equiv=\"refresh\" content=\"0; url=http://guild.the-reincarnation.com/encyclopedia/spell/101.html\"> \n"<< endl;
makeHTML << "</head> \n" << endl;
makeHTML << "<body bgcolor=\"black\"> \n" << endl;
makeHTML << "<h2 stlye=\"color:white\">Redirecting</h2> \n" << endl;
makeHTML << "</body> \n" << endl;
makeHTML << "</html> \n" << endl;
}
} while (pageName != "exit");
return 0;
}