C++ Setup & Hello World
Lesson 1: C++ Setup & Hello World
Welcome to your C++ journey! By the end of this lesson, you’ll have a working C++ environment and will have written and run your first program.
What You’ll Learn
- What C++ is and why it matters for game development
- How to install a C++ compiler on Windows, macOS, or Linux
- How to write, compile, and run “Hello, World!”
- Basic program structure explained
Why C++ for Game Development?
C++ is the industry standard for game development because it gives you:
- Raw performance — direct memory control with no garbage collector
- Hardware access — talk to GPUs, controllers, and audio devices
- Portability — run on consoles (PlayStation, Xbox, Switch), PC, and mobile
- Ecosystem — Unreal Engine, custom engines, and most AAA studios use C++
If you want to build games that push hardware to its limits, C++ is your language.
Step 1: Install a Compiler
A compiler turns your human-readable C++ code into machine code the computer understands.
Windows
Option A: Visual Studio Community (Recommended for beginners)
- Download Visual Studio Community (free)
- During installation, select “Desktop development with C++”
- Click Install
Option B: MinGW (Lightweight)
- Download MSYS2
- Follow the installation guide
- Open MSYS2 terminal and run:
pacman -S mingw-w64-ucrt-x86_64-gcc
macOS
Install Xcode Command Line Tools:
xcode-select --install
Or use Homebrew:
brew install gcc
Linux (Ubuntu/Debian)
sudo apt update
sudo apt install g++ build-essential
Step 2: Verify Your Installation
Open a terminal (Command Prompt on Windows, Terminal on macOS/Linux) and run:
g++ --version
You should see something like:
g++ (Ubuntu 13.2.0-4ubuntu3) 13.2.0
If you see a version number, you’re ready!
Step 3: Choose a Code Editor
You can write C++ in any text editor, but these make your life easier:
| Editor | Best For | Free? |
|---|---|---|
| VS Code | Lightweight + extensible | ✅ |
| Visual Studio | Windows + heavy debugging | ✅ (Community) |
| CLion | Advanced features | ❌ (Free trial) |
| Code::Blocks | Simple, all-in-one | ✅ |
For this tutorial, I’ll use VS Code with the C++ extension:
- Download VS Code
- Open VS Code
- Go to Extensions (Ctrl+Shift+X)
- Search for “C++” and install Microsoft’s C++ extension
Step 4: Your First C++ Program
Create a new folder for your C++ projects:
mkdir cpp-projects
cd cpp-projects
Create a file called hello.cpp and open it in your editor.
The Code
Type this exactly:
#include <iostream>
int main() {
std::cout << "Hello, World!" << std::endl;
return 0;
}
Important: C++ is case-sensitive. main is not the same as Main.
Step 5: Understanding the Code
Let’s break down every line:
| Line | Explanation |
|---|---|
#include <iostream> | Includes the Input/Output stream library. This gives us std::cout |
int main() { | Every C++ program starts here. int means the function returns an integer |
std::cout << "Hello, World!" << std::endl; | Prints text to the console. std::cout = “character output”, << = “send to”, std::endl = new line |
return 0; | Tells the operating system “everything worked fine” |
} | Closes the main function |
What is std::?
std:: is the standard namespace. It tells C++ “use the cout from the standard library.” You’ll see this everywhere. Later, you can add using namespace std; to avoid typing std:: every time.
Step 6: Compile and Run
In your terminal, navigate to where hello.cpp is saved:
cd /path/to/cpp-projects
Compile
g++ hello.cpp -o hello
This tells g++ to:
hello.cpp— compile this file-o hello— output an executable namedhello
Run
Windows:
hello.exe
macOS / Linux:
./hello
Expected Output
Hello, World!
🎉 Congratulations! You just wrote and ran your first C++ program.
Step 7: Common Errors & Fixes
”g++ is not recognized”
- You didn’t install a compiler, or it’s not in your PATH
- Reinstall and check “Add to PATH” during installation
”expected ’;’ before…”
- You forgot a semicolon at the end of a line
- C++ requires
;after almost every statement
“‘cout’ is not a member of ‘std’”
- You forgot
#include <iostream>
”main must return int”
- C++ doesn’t allow
void main()— always useint main()
Practice: Modify the Code
Try these small changes and see what happens:
-
Print multiple lines:
std::cout << "Hello" << std::endl; std::cout << "World!" << std::endl; -
Print without new line:
std::cout << "Hello "; std::cout << "World!"; -
Print a number:
std::cout << 42 << std::endl;
Summary
In this lesson, you learned:
✅ How to install a C++ compiler on your OS
✅ Which editors work best for C++ development
✅ The structure of a basic C++ program
✅ How to compile and run code from the terminal
✅ Common errors and how to fix them
What’s Next?
Next lesson: Variables and Data Types — where we’ll store numbers, text, and true/false values to build more interesting programs.
Resources
- Official C++ Reference
- LearnCpp.com — excellent free tutorial
- Compiler Explorer — see how C++ becomes assembly
Practice Task: Modify Hello World to print your name, age, and favorite game. Compile and run it. Then change the return 0; to return 1; and see if anything different happens.
Questions? Feel free to contact me.
📖 Read this lesson in Russian