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
| System | Easiest option |
|---|---|
| Windows | Code::Blocks "mingw-setup" installer (includes g++), or Visual Studio Community with "Desktop development with C++" |
| Mac | xcode-select --install in Terminal (installs Clang) |
| Linux | sudo 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++20uses the modern C++20 standard (use-std=c++17if your compiler is older).-Wallturns on warnings.-o hellonames the program. On Windows, run it withhello.
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. 🙂
By Sir Reyel · Last updated 2026-12-04