Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The easiest interaction model to bring to the web is an application that takes its input up front and produces its output on <code>stdout</code>. In this situation, as the unknown poster mentioned, you could use <a href="http://en.wikipedia.org/wiki/Common_Gateway_Interface" rel="nofollow noreferrer">CGI</a>. But due to the nature of CGI, this will only work (in the simplest sense) if all the information is collected from the user in one page, sent to the application and the results returned in one page. This is because each invocation of a page using CGI spawns a new indepdent process to serve the request. (There are other more efficient solutions now, such as <a href="http://en.wikipedia.org/wiki/FastCGI" rel="nofollow noreferrer">FastCGI</a> which keeps a pool of processes around.) If your application is interactive, in that it collects some information, presents some results, prints some options, collects some more user input, then produces more results, it will need to be adapted.</p> <p>Here is about the simplest possible CGI program in C++:</p> <pre><code>#include &lt;iostream&gt; int main(int argc, char* argv[]) { std::cout &lt;&lt; "Content-type: text/plain\n" &lt;&lt; std::endl; std::cout &lt;&lt; "Hello, CGI World!" &lt;&lt; std::endl; } </code></pre> <p>All it does is return the content type followed by a blank line, then the actual content with the usual boring greeting.</p> <p>To accept user input, you would write a form in HTML, and the <code>POST</code> target would be your application. It will be passed a string containing the parameters of the request, in the usual HTTP style:</p> <pre><code>foo.cgi?QTY=123&amp;N=41&amp;DESC=Simple+Junk </code></pre> <p>You would then need to parse the query string (which is passed to the program via the <code>QUERY_STRING</code> environment variable) to gather the input fields from the form to pass to your application. Beware, as parsing parameter strings is the source of a great number of security exploits. It would definitely be worthwhile finding a CGI library for C++ (a Google search reveals many) that does the parsing for you. The query data can be obtained with:</p> <pre><code>const char* data = getenv("QUERY_STRING"); </code></pre> <p>So at a minimum, you would need to change your application to accept its input from a query string of <code>name=value</code> pairs. You don't even need to generate HTML if you don't want to; simply return the content type as <code>text/plain</code> to begin with. Then you can improve it later with HTML (and change the content type accordingly).</p> <p>There are other more sophisticated solutions, including entire web frameworks such as <a href="http://www.webtoolkit.eu/wt" rel="nofollow noreferrer">Wt</a>. But that would involve considerable changes to your apps, which you said you wished to avoid.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload