Cookies can be generated using the cgixx::cookie class. When instantiating a cookie, you must specify either a name for the cookie, or another cgixx::cookie to copy. Specifying the cgixx::cgi environment in the cgixx::cookie constructor will automatically populate the domain and path cookie values.
#include <cgixx/cgixx.h>
#include <iostream>
#include <string>
int main(int argc, char* argv)
{
cgixx::cgi cgi;
cgixx::header header;
std::string val;
// Instantiate a couple of cookies
cgixx::cookie a(cgi, "a", "1"), b(cgi, "b", "2");
// Add the cookies to the header.
header.addcookie(a);
header.addcookie(b);
// Print the header (including cookies)
std::cout << header.get();
// Print some HTML
std::cout <<
"<HTML><HEAD><TITLE>Test page</TITLE><HEAD>\n"
"<BODY><H1>Test Page</H1><HR>\n";
// Get cookies already assigned to the user agent
cgixx::cgi::identifierlist idlist;
cgi.getcookielist(idlist);
// Print the current list of cookies returned by the user agent
cgixx::cgi::identifierlist::iterator it(idlist.begin()),
end(idlist.end());
for (; it != end; ++it)
{
while (!cgi.getcookie(*it, val))
std::cout << *it << ": " << val << "<br>\n";
}
std::cout << "\n"
"</BODY></HTML>"
<< std::endl;
return 0;
}