Main  /  Edit  /  History  /   /  Users Area

Tutorial: "Hello World!" - Code

First we need to include one header of cppcms library:

#include <cppcms/application.h>
#include <iostream>
using namespace std;
using namespace cppcms;

Then we implement our quite simple and useless web application:

class my_hello_world : public application {
    my_hello_world(worker_thread &worker) :
    virtual void main();


  1. The base class cppcms::application receives a reference to cppcms::worker_thread object as parameter in its constructor, thus, you should implement a constructor that receives this parameter and passes it to base class.
  2. The virtual member function "main" is actually the function that is called upon any page request.
void my_hello_world::main()
          "  <h1>Hello World</h1>\n"

This function writes to cppcms::application::cout (not std::cout) a "Hello World" html message.

Remark: Usually you will not use "cout" directly, it is usually used as an output for template engine.

int main(int argc,char ** argv)
    try {
        manager app(argc,argv);
        app.set_worker(new application_factory<my_hello_world>());
    catch(std::exception const &e) {

We create an object of type cppcms::manager that controls general settings like: web server API, run time mode. cache and more. It parses command line arguments, reads configuration file and defines all required properties.

Then we need to create a factory class that would create objects that would process requests. The template cppcms::application_factory defines such factory for your class my_hello_world. Now we can call the main loop of our application execute()

This framework throws exceptions of type cppcms::cppcms_error that are derived from std::runtime_error and can be catch using std::exception.

Now we can build our application running:

gcc hello.cpp -o hello.fcgi -lcppcms


CppCMS is a web development framework for performance demanding applications.

Support This Project Logo

Поддержать проект

CppCMS needs You


Main Page

Valid CSS | Valid XHTML 1.0