C++ with CGI

Before doing example, You have to configure cgi-bin with apache server.
If its done then try your first example.

Open an empty file and write following c++ code.

#include <iostream>
using namespace std;

int main ()

cout << "Content-type:text/html\n\n";
cout << "Hello World - First CGI Program";

return 0;

Now save this file with .cpp extension(example.cpp) in public_html/cgi-bin folder.
Then compile that program.
$ g++ -o example example.cpp

This will create example file which is executable.
Then open browser and open following link”


This will show you following o/p on browser.

Hello World – First CGI Program

If you find any problem then share it as comments.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s