Aral Code

Getting Started Lesson 2 of 17

Getting Started with C++ — Install a Compiler and Run Code

Install g++ or Clang, compile and run a C++ program from the command line, choose an IDE such as Code::Blocks, VS Code or Visual Studio, and read compiler errors.

You need a C++ compiler to turn your code into a program. The free choices are g++ (part of GCC), Clang, and Microsoft's compiler in Visual Studio.

Installing a compiler

SystemEasiest option
WindowsCode::Blocks "mingw-setup" installer (includes g++), or Visual Studio Community with "Desktop development with C++"
Macxcode-select --install in Terminal (installs Clang)
Linuxsudo apt install g++

Compile and run

Save this as hello.cpp:

#include <iostream>
using namespace std;

int main() {
    cout << "Hello from C++!" << endl;
    cout << "Grade 11 - STEM" << endl;
    return 0;
}
g++ -std=c++20 -Wall hello.cpp -o hello
./hello

Output

Hello from C++!
Grade 11 - STEM
  • -std=c++20 uses the modern C++20 standard (use -std=c++17 if your compiler is older).
  • -Wall turns on warnings.
  • -o hello names the program. On Windows, run it with hello.

IDEs

  • Code::Blocks: popular in Philippine schools. New → Project → Console application → C++. Press F9 to build and run.
  • Visual Studio Community (Windows): full-featured and free for students.
  • VS Code: install the "C/C++" extension and a compiler, then use the Run button.
  • Dev-C++: lightweight; make sure it's a recent version.

Reading errors

#include <iostream>
using namespace std;

int main() {
    cout << "Total: " << totl << endl;
    return 0;
}

Error

hello.cpp:5:25: error: use of undeclared identifier 'totl'
    cout << "Total: " << totl << endl;
                         ^
1 error generated.

The compiler shows the file, line 5, column 25, and the problem: totl doesn't exist (a typo for total). Fix the first error first; later errors are often caused by it.

A tiny interactive program

#include <iostream>
#include <string>
using namespace std;

int main() {
    string name;
    cout << "What's your name? ";
    getline(cin, name);
    cout << "Welcome to C++, " << name << "!" << endl;
    return 0;
}

Output

What's your name? Ana Reyes
Welcome to C++, Ana Reyes!

You'll learn cin and getline properly in the next lesson.

Quick Quiz

Check what you learned. Walang grade ito, practice lang. 🙂

1. What file extension do C++ source files usually use?
2. What does -std=c++20 do?
3. Which key builds and runs in Code::Blocks?
4. With many compiler errors, which should you fix first?

By Sir Reyel · Last updated 2026-12-04