#include #include //for the function getenv #include //for class stringstream #include "cgi.h" using namespace std; cgi::cgi() { const char *const p {getenv("CONTENT_LENGTH")}; if (p == nullptr) { cout << "Environment has no CONTENT_LENGTH\n"; return; } const int n {stoi(p)}; //"string to integer" string s; s.resize(n); //Make s big enough to hold all the data. cin.read(&s[0], n); //Read n bytes of data into s. if (!cin) { cout << "Unable to input " << n << " bytes.\n"; return; } stringstream ss {s}; //We can use ss to read the characters from s. string line; while (getline(ss, line, '&')) { const size_t pos {line.find('=')}; if (pos != std::string::npos) { //If we found the '=', //The key is everything before the '='; //the value is everthing after the '='. const string key {line.substr(0, pos)}; const string value {line.substr(pos + 1)}; m[key] = value; //m.operator[](key) = value; } } }