#include #include #include // for getenv, EXIT_SUCCESS, EXIT_FAILURE #include // for class string #include // for class map using namespace std; map m; bool get_input(); string display_color(const string& s); int main() { cout << "Content-type: text/html\n\n"; cout << "\n" "\n" "\n" "Personal Information\n" "\n" "\n" "\n" "

Personal Information

\n"; if (get_input()) { cout << "
    \n"; for (const auto& pair : m) { cout << "
  1. " << pair.first << " = " << pair.second << display_color(pair.second) << "
  2. \n"; } cout << "
\n"; } else { cout << "

Error: Unable to retrieve form data.

\n"; } cout << "\n" "\n"; return EXIT_SUCCESS; } bool get_input() { const char* const p = getenv("CONTENT_LENGTH"); if (p == nullptr) { cout << "Environment has no CONTENT_LENGTH\n"; return false; } const int content_length = stoi(p); string s(content_length, '\0'); cin.read(&s[0], content_length); if (!cin) { cout << "Unable to input " << content_length << " bytes.\n"; return false; } stringstream ss(s); string line; while (getline(ss, line, '&')) { const size_t pos = line.find('='); if (pos != string::npos) { const string key = line.substr(0, pos); const string value = line.substr(pos + 1); m[key] = value; } } return true; } string display_color(const string& s) { string html; if (s.substr(0, 3) == "%23" && s.size() == 3 + 6) { html = "      "; } return html; }