← C++

C++ · 01 / 24

Install C++ and run your first program

Distinguish source text, the compiler and the executable, then run your first C++ program.

  • Small
  • Basics
  • 30 min

Prerequisites: No prior knowledge required.

In this tutorial
  1. Prepare the tools
  2. Understand the file
  3. Compile and execute
  4. Exercise and solution
  5. Project context and sources

Download learning package

Setup and verification

GCC with C++20 and CMake 3.25 or newer. Python 3 is also required for the common verification entry point. Extract the learning package into a new folder and run python3 run_checks.py there. The script copies the included files into a temporary learning directory. It verifies the example and then the supplied solution there, preserving the original files. Required packages are downloaded on the first run.

Verified on 2026-10-21 on Linux x86_64. The console example and exercise solution are executed. Expected output is shown in the article.

A program is a sequence of instructions for a computer. C++ is the language used to write those instructions. A file ending in .cpp initially contains ordinary text. A compiler translates that text into an executable. An editor changes files, while a terminal runs commands. These tools have different responsibilities.

FactoryForge will eventually have a graphical interface. We begin with console output so that no window library or previous programming knowledge is needed. Save and compile the source again after each change. Running an old executable does not read the new source automatically.

Package contents and individual files

01Prepare the tools

On Ubuntu install GCC and check g++ --version. GCC 13 matches this project. On Windows install Visual Studio 2022 with the Desktop development with C++ workload and open its Developer Command Prompt. The cl command must be available there. Any plain-text editor can be used to write the source.

02Understand the file

Save the example as main.cpp. The include line makes standard output available. main is the entry point. Braces delimit its body. std::cout writes text. The expression \n produces a newline. A semicolon ends a statement. main can finish successfully without an explicit return statement.

main.cpp · cppOpen file
#include <iostream>
int main() { std::cout << "Hello, FactoryForge!\n"; }

Run / check

g++ -std=c++20 main.cpp -o lesson
./lesson

03Compile and execute

On Linux use g++ -std=c++20 main.cpp -o lesson followed by ./lesson. On Windows use cl /std:c++20 /EHsc /utf-8 main.cpp followed by main.exe. C++20 selects the language version. Change the greeting, save, compile again and rerun the executable.

Expected result

Hello, FactoryForge!

Your exercise

Add a second output line naming your first warehouse. Run the old executable before recompiling, then compare the result after recompilation.

Show the solution and explanation

Add another std::cout statement inside main with text and a newline. The existing executable remains unchanged until compilation succeeds. Afterwards both lines appear in statement order. This verifies the difference between saved source text and the machine program that actually runs.

solution/main.cpp · cppOpen file
#include <iostream>
int main() {
  std::cout << "Hello, FactoryForge!\n";
  std::cout << "Warehouse North\n";
}

Project context and sources

The first six examples are standalone teaching programs. Lessons 7 through 9 use the complete FactoryForge source snapshot. Code, exercises and verified simplifications are explained separately. The project page provides a source ZIP while the GitHub repository is not yet published.