My c++ project any advice please ? (website maker)

Hello i know a decent amount of c++. Now what my program is going to be is dos windows and a input of commands that make web pages.For example if i typed in new-back color-blue that would make the background color blue.I will be using fstream and string.

heres a prototype of my code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>

using namespace std;
void skipline();
void basic();

int main () 
{
  cout << "Creat html doc press enter";
  cin.get();

 

  basic();

  cin.get();
  return 0;
}

void skipline()
{
cout << "\n";	
}

void basic()
{
	 ofstream myfile;
  myfile.open ("website.html");
	
  myfile << "<html>" << endl;

  myfile << "<header> <title> testing </title> </header>" << endl; //Header line of code.

  myfile << "<body bgcolor=pink>\n" << endl;
  skipline();
  myfile << "<center>\n";
  myfile << "<p>hello world!</p>";
  myfile << "</center>\n";
  myfile << "</body>\n" << endl;
  skipline();
  myfile << "</html>"<< endl;

  
  myfile.close();
}
I suggest you make an intermediate representation of your html, for example
1
2
3
4
5
6
struct Tag{
   string name;
   Tag* parent;
   map<string, string> parameters;
   vector<Tag> children;
};
(you need something a bit more intelligent though, as this doesn't take care of plain text)
Then add functions to move around this tree (have a Tag* current), print current subtree, add and remove children or parameters. The hard part is to figure out how to conveniently address tags. As there could, for example, be several <p> in your <center>, you need to tell which one you're trying to work with. You could give all tags implicit id's, or you could only access tags with commands "goto_parent", "goto_first_child", "goto_next_sibling", or you could access them by their positions in children vector. Either way, it isn't going to be too comfortable.
Topic archived. No new replies allowed.