cout << "<body>\n";
...
cout << getenv("QUERY_STRING");
cout << "</body>\n";
FWIW I wrote an article about HTML escaping and shell here: http://www.oilshell.org/blog/2017/09/19.htmlFollowup: http://www.oilshell.org/blog/2017/09/29.html
Also if you want to use a native language for web sites (which I don't), Go is a better choice, as the standard library has html/template which protects you from naive injections: