1. Why Setup Matters
Before writing C++ programs, you need a development environment — the tools that allow you to write, compile, and run C++ code.
Without a proper setup, your code will not run, and debugging becomes difficult. A good setup makes learning and experimentation much smoother.
2. Tools for C++ Beginners
Students can start with beginner-friendly or free tools:
-
Visual Studio Complete IDE for Windows; supports project management, debugging, and compilation.
-
VS Code + C++ Extensions Lightweight editor; works on Windows, Mac, Linux. Add the “C++ extension” for compiling.
-
Code::Blocks Cross-platform IDE with built-in compiler. Great for beginners.
-
Online Compilers Websites like Replit, CPP.sh, or Ideone allow you to write and run code without installing anything.
Tip for Beginners: Start with an online compiler first to avoid installation problems.
3. Anatomy of a C++ Program
A C++ program has a structured layout:
#include <iostream> // Libraries and headers
int main() { // Entry point
std::cout << "Welcome to C++!" << std::endl; // Output
return 0; // End program
}
Key Points
#include <iostream>→ Adds pre-written code for input/output operations.int main()→ All C++ programs start here; the entry point of execution.std::cout→ Prints information to the screen.return 0;→ Signals successful program termination.
4. Variables and Data Types
Variables are containers for storing data.
int age = 20; // Whole number
double height = 5.9; // Decimal number
char grade = 'A'; // Single character
std::string name = "Andy"; // Text
bool isStudent = true; // True or false
Explanation:
int→ integersdouble→ floating-point numberschar→ single charactersstring→ textbool→ true/false values
5. Basic Input
std::string username;
std::cout << "Enter your name: ";
std::cin >> username;
std::cout << "Hello, " << username << "!";
Explanation:
cin→ takes input from the usercout→ displays output
6. Why Understanding Program Structure Matters
- Helps you organize your code.
- Makes it easier to read and debug.
- Lays a foundation for functions, loops, and object-oriented programming.
Quiz
- Name two tools for writing C++ programs.
- What is a variable? Give an example.
- Write a program that asks for a user’s name and prints it.
- Why must statements end with a semicolon
;?