Modern C++: The Good Parts/Hello, world!

What are we waiting for? Here's your first C++ program. Save it in your editor (such as Qt Creator or Visual Studio), compile or build it, and run the executable. This will prove whether your compiler is working, which will be rather important for later exercises.


#include <iostream>
#include <string>

int main()
	std::cout << "Hello, world!\n";


Those first two lines tell the compiler what includes (pre-existing code) we need. int main is required for any C++ program, and the logic inside the curly brackets is everything that will be done. The particular way that C++ requires us to arrange code is called its syntax.

In this case, we send the text "Hello, world!" to the console.

These first two chapters have been kept short to allow for complications with setting up your compiler, but following chapters will pick up the pace.


files containing code that we can use in our own program.
the specific rules of a language, or basically what the language looks like.
Modern C++: The Good Parts
 ← Getting a compiler Hello, world! Anatomy of a global greeting →