C++ Get Started
Before you can run C++ code, you need a way to write it and a compiler to turn it into a program. This page walks you through the tools you need and shows you how to build and run your very first C++ program.
What you need
To start writing C++ you need two things: a text editor to type your code, and a compiler that converts your code into a runnable program. Many people use a code editor that bundles both together, such as Visual Studio, Visual Studio Code, or Code::Blocks.
- A text editor or IDE (integrated development environment) to write the code.
- A C++ compiler such as GCC (g++), Clang, or the Microsoft Visual C++ compiler.
- A terminal or the editor's Run button to launch your finished program.
Your first program
C++ source files usually end with the .cpp extension. Create a file named hello.cpp and type the following code into it.
hello.cpp
#include <iostream>
using namespace std;
int main() {
cout << "Hello World!";
return 0;
}Compiling and running
A compiler reads your .cpp file and creates an executable program that your computer can run. If you use the GCC compiler from a terminal, the two steps look like this.
Build and run from the terminal
g++ hello.cpp -o hello
./helloExercise: C++ Get Started
Which file extension is standard for a C++ source file?