Напишим простой CGI спомощью моей библиотеки см. https://cloud.mail.ru/public/UWRh/PfovNYdbx, так будет выглядеть результат:
https://i.ibb.co/Z6TymBn/cgi-script-result-17-05-15-12-2021-min.jpg

Файл tag.h:

Код:
#ifndef TAG_H
#define TAG_H
#include "control.hpp"
#include <iostream>

using namespace std;

class Tag {
   private:
      string id;
      string tagname;
      string attribute;
      string innerHTML;
   public:
      Tag(string tagname);
      Tag(string tagname, string id);
      void setAttribute(string attribute);
      string getAttribute();
      void setInnerHTML(string innerHTML);
      string getInnerHTML();
      string render();
};
#endif

Файл tag.cpp:

Код:
#include "tag.h"

Tag::Tag(string tagname) {
   this->tagname = tagname;
}

Tag::Tag(string tagname, string id) {
   this->tagname = tagname;
   this->id = id;
}

void Tag::setAttribute(string attribute) {
   this->attribute = attribute;
}

string Tag::getAttribute() {
   return this->attribute;
}

void Tag::setInnerHTML(string innerHTML) {
   this->innerHTML = innerHTML;
}

string Tag::getInnerHTML() {
   return this->innerHTML;
}

string Tag::render() {
  string temp = "";
  if(this->innerHTML.length() > 0)
    temp = this->innerHTML;
  string buffer = "<" + this->tagname + " " + this->attribute + " " + ">"+ temp + "<" + this->tagname + "/>";
  return buffer;
}

Файл textbox.h:

Код:
#ifndef TEXTBOX_H
#define TEXTBOX_H
#include "control.hpp"
#include <iostream>

using namespace std;

class TextBox {
   private:
      string id;
      string text;
      string attribute;
   public:
      TextBox(string id);
      void setText(string text);
      string getText();
      void setAttribute(string attribute);
      string getAttribute();
      string render();
};
#endif

Файл textbox.cpp:

Код:
#include "textbox.h"

TextBox::TextBox(string id) {
   this->id = id;
}

void TextBox::setText(string text) {
   this->text = text;
}

string TextBox::getText() {
   return this->text;
}

void TextBox::setAttribute(string attribute) {
   this->attribute = attribute;
}

string TextBox::getAttribute() {
   return this->attribute;
}

string TextBox::render() {
  string temp = "";
  if(this->text.length() > 0)
    temp = "value=\"" + this->text + "\"";
  string buffer = "<input type=\"text\" " + this->attribute + " " + temp + "/>";
  return buffer;
}

Файл button.h:

Код:
#ifndef BUTTON_H
#define BUTTON_H
#include "control.hpp"
#include <iostream>

using namespace std;

class Button {
   private:
      string id;
      string text;
      string attribute;
   public:
      Button(string id);
      void setText(string text);
      string getText();
      void setAttribute(string attribute);
      string getAttribute();
      string render();
};
#endif

Файл button.cpp:

Код:
#include "button.h"

Button::Button(string id) {
   this->id = id;
}

void Button::setText(string text) {
   this->text = text;
}

string Button::getText() {
   return this->text;
}

void Button::setAttribute(string attribute) {
   this->attribute = attribute;
}

string Button::getAttribute() {
   return this->attribute;
}

string Button::render() {
  string temp = "";
  if(this->text.length() > 0)
    temp = "value=\"" + this->text + "\"";
  string buffer = "<input type=\"button\" " + this->attribute + " " + temp + "/>";
  return buffer;
}

Файл main.cpp, это главный файл:

Код:
#include "textbox.h"
#include "button.h"
#include "tag.h"

#include <control.hpp>
#include <response.hpp>
#include <request.hpp>
#include <htmlinput.hpp>
#include <iostream>
#include <string>

using namespace std;

int main(int argc, char** argv) { 
  const string header = "<!DOCTYPE html>\n"
  "<html>"
  "\n<head>"
  "\n<title>Demo CGI</title>"
  "\n</head>"
  "\n<body>"
  "\n";
  
  const string footer = "\n</body>"
                    "\n</html>";

  try {
    Response *r = new Response();
    r->set_content_type("text/html");
    r->begin_html();
    r->add_text(header);
    
    Tag *div1 = new Tag("div", "div1");    
    div1->setInnerHTML("Hello!");
    Tag *bold = new Tag("b");
    bold->setInnerHTML(div1->render());
    r->add_text(bold->render());
    Tag *h1 = new Tag("h1");
    h1->setInnerHTML("Hello World!");
    r->add_text(h1->render());
    
    r->add_text(footer);
    r->render();
  }
  catch(const exception& e) {
     cout << header 
     << "Exception " 
     << e.what() 
     << "position:" 
     << footer
     << endl;
  }
  return 0;
}