Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Howto use C++ and GNU cgicc in Gentoo
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
jpreston
n00b
n00b


Joined: 22 Apr 2004
Posts: 18
Location: Columbus, OH

PostPosted: Sat Feb 26, 2005 6:58 pm    Post subject: Howto use C++ and GNU cgicc in Gentoo Reply with quote

Hey,

I thought I would just post a new howto.

Problem, documentation is lacking on using GNU's cgicc library in Gentoo.

Quickly install the library.

Code:

emerge dev-libs/cgicc


Write some HTML ;-)

Code:

<!-- test.html -->
<html>
  <head>
    <title>cgicc test</title>
  </head>
  <body>

    <form method="post" action="http://change_this_path/cgi-bin/foo.cgi">
      Your name : <input type="text" name="name" /><br />
      Your age : <input type="text" name="age" /><br />
      Your sex : <input type="radio" name="sex" value="male"checked="checked" />Male
     <input type="radio" name="sex" value="female" />Female <br />
    </form>
  </body>
</html>


Write some source code ;-)

Code:

/* example.cpp from http://www.cgicc.org/doc/cgicc_tutorial.html */

#include <iostream>
#include <vector>
#include <string>

#include <Cgicc.h>
#include <HTTPHTMLHeader.h>
#include <HTMLClasses.h>

using namespace std;
using namespace cgicc;

int
main(int argc,
     char **argv)
{
   try {
      Cgicc cgi;

      // Send HTTP header
      cout << HTTPHTMLHeader() << endl;

      // Set up the HTML document
      cout << html() << head(title("Cgicc example")) << endl;
      cout << body() << endl;

      // Print out the submitted element
      form_iterator name = cgi.getElement("name");
      if(name != cgi.getElements().end()) {
         cout << "Your name: " << **name << endl;
      }

      // Close the HTML document
      cout << body() << html();
   }
   catch(exception& e) {
      // handle any errors - omitted for brevity
   }
}


Compile and link it! ;-)

Code:

$ g++ example.cpp -o example -I /usr/include/cgicc -lcgicc


Make sure you update all the paths and have Apache setup properly, then point a web browser to the test.html file on your sever and viola!

Hope this helps someone else out there ;-)

Joshua Preston.
Back to top
View user's profile Send private message
Sqeaky
Tux's lil' helper
Tux's lil' helper


Joined: 31 Dec 2003
Posts: 105

PostPosted: Tue Apr 26, 2005 4:22 am    Post subject: Reply with quote

Thank I found this extremely helpful
Back to top
View user's profile Send private message
codergeek42
Bodhisattva
Bodhisattva


Joined: 05 Apr 2004
Posts: 5142
Location: Anaheim, CA (USA)

PostPosted: Wed Apr 27, 2005 12:10 am    Post subject: Reply with quote

Heh. That's cool. 8) Thanks.
_________________
~~ Peter: Programmer, Mathematician, STEM & Free Software Advocate, Enlightened Agent, Transhumanist, Fedora contributor
Who am I? :: EFF & FSF
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum