Set Up Your Language · 8 of 14
Setting Up C++
C++ is the language behind most games and game engines, web browsers and heavy software such as video editors, where speed matters most. C++ is a compiled language: a program called a compiler turns your text into a .exe file that Windows runs. We install the free GCC compiler (its C++ command is g++) through MSYS2, a well-known free collection of programming tools for Windows.
New to all this? Read Before you start on the main page first: it shows how to open Terminal, make a folder for your code, and see file name endings. It takes five minutes and prevents most problems.
1 What to download, and from where
Download only from msys2.org, the official MSYS2 website (GCC itself is a GNU project, gcc.gnu.org). Other download sites can bundle unwanted software.
- Go to msys2.org, the official MSYS2 site. Under Installation, click the installer link (a file named like
msys2-x86_64-20xxxxxx.exe).
2 Install it on Windows
- Open the downloaded file. Click Next on each screen and keep the suggested folder
C:\msys64. Click Finish at the end. - A black window titled UCRT64 (or MSYS2 UCRT64) opens. This is MSYS2's own terminal. If it does not open, press the Windows key, type MSYS2 UCRT64 and open it.
- In that window, type this line and press Enter (copy it exactly):It lists what it will download and asks
pacman -S --needed mingw-w64-ucrt-x86_64-gccProceed with installation? [Y/n]. Press Enter to say yes. It downloads for a minute or two. - Add the compiler's folder
C:\msys64\ucrt64\binto your PATH, so Windows can find it from any Terminal (step-by-step instructions). Then close and reopen Terminal.
Another way: Microsoft's free Visual Studio Community (visualstudio.microsoft.com, choose the Desktop development with C++ option when installing) is a large all-in-one program with its own compiler. It is a bigger download, but some courses use it.
3 Check that it worked
Close every Terminal window you have open and open a new one. A Terminal that was already open does not know about programs installed after it started. Then type this and press Enter:
g++ --versionWhat you will see: A first line with Built by MSYS2 project and a version number. Run this in a normal Terminal, not the MSYS2 window, to prove the PATH step worked.
g++.exe (Rev8, Built by MSYS2 project) 15.2.0 Copyright (C) 2025 Free Software Foundation, Inc.
If you see an error such as "is not recognized" instead, look at the common mistakes at the bottom of this page.
4 Write and save your first program
A program is just a text file. You can write it in Notepad, which comes with Windows. (Later you may like the free Visual Studio Code editor from code.visualstudio.com, which colours the code and helps spot mistakes.)
- Open Notepad (press the Windows key, type Notepad, press Enter).
- Type the program below, or click Copy and paste it in with Ctrl + V. Every symbol matters, so copy it exactly.
#include <iostream> int main() { std::cout << "Hello, World!" << std::endl; return 0; } - In Notepad choose File → Save as. Go to your
C:\codefolder. Set Save as type to All files (*.*), type the file namehello.cppexactly as shown, including the dot and the ending, and click Save.
#include <iostream> brings in the part of C++ that handles input and output. main is where the program starts. std::cout << sends text to the screen and std::endl ends the line.
Do not use Word. Word saves extra formatting and changes straight quotes " into curly ones “ ”, which no programming language accepts.
5 Run it and see the result
Two steps: build (compile) the program into an .exe, then run the .exe.
Open File Explorer, go into your C:\code folder, right-click an empty part of the window and choose Open in Terminal. (More ways to open Terminal.) If Terminal was already open from the check above and is in another folder, type cd C:\code and press Enter.
Type these lines one at a time, pressing Enter after each:
g++ hello.cpp -o hello.exe
.\hello.exeWhat you will see: the words below on a new line. That is your program running.
Hello, World!
-o hello.exe names the output file. Each time you change hello.cpp, run the first line again, or you will still be running the old program.
Congratulations: you have written and run a C++ program.
6 Common beginner mistakes and how to fix them
Error messages look alarming but are usually precise: read the first line, and look for a line number. If you are stuck, copy the whole error message and paste it into an AI assistant along with your code, and ask what it means.
undefined reference to `std::cout'
Why: you built a C++ file with gcc, the C command.
Fix: use g++ for C++ files.
error: expected ';' before '}' token
Why: a semicolon is missing at the end of a line. The error shows the file, line number and position, for example hello.cpp:4:47.
Fix: look at that line (or the line just before it) and add the ;.
'g++' is not recognized as an internal or external command
Why: Windows cannot find the program. Either the Terminal was open before you installed it, or the program's folder is not on the PATH (the list of folders Windows searches for commands).
Fix: Close every Terminal window you have open and open a new one. A Terminal that was already open does not know about programs installed after it started. If it still fails, restart the computer, then check the folder is on the PATH (how to check and add it). The folder to add is C:\msys64\ucrt64\bin.