O'Reilly logo

Beginning C++ Programming by Richard Grimes

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

A simple example

The simplest C++ program is shown here:

    #include <iostream>      // The entry point of the program     int main()     {         std::cout << "Hello, world!n";     }

The first point to make is that the line starting with // is a comment. All the text until the end of the line is ignored by the compiler. If you want to have multiline comments, every line must start with //. You can also use C comments. A C comment starts with /* and ends with */ and everything between these two symbols is a comment, including line breaks.

C comments are a quick way to comment out a portion of your code.

The braces, {}, indicates a code block; in this case, the C++ code is for the function main. We know that this is a function because of the basic format: first, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required