Ch2.1: Hello World

Your First Program (Minimal)

Now that you know how to compile code, let’s write your very first C++ program. This program will simply print Hello World on the screen.


#include <fast_io.h>

int main()
{
    using namespace ::fast_io::iomnp;
    print("Hello World\n");
}

Your First Program (With Comments)

Here’s the same program again, but with comments explaining each part:


// Single-line comment: starts with //

// Multi-line comment:
/*
   This is a multi-line comment.
   It starts with /* and ends with */.
*/

// Documentation-style comments:
/// One-line documentation comment
/**
 * Multi-line documentation comment
 */

#include <fast_io.h>  // include the fast_io library

// Every C++ program starts with a main function.
int main()
{
    // "using namespace ::fast_io::iomnp;" lets us use fast_io functions directly.
    using namespace ::fast_io::iomnp;

    // "print" writes text to the screen.
    print("Hello World\n");
}

Breaking It Down

Try It Yourself

Save the minimal code above as main.cpp. After compilation and then run it you should see:

Hello World