C++ Programming - Complete Guide
From C foundations to OOP, STL, memory and modern C++ - exam and
interview ready
Complete Study Guide | Key Concepts | Examples | Practice Questions
, 1. C++ Basics and I/O
C++ extends C with classes, templates and the STL. It compiles to native code - fast, with manual memory control.
#include <iostream>
#include <string>
using namespace std;
int main() {
string name;
cout << "Enter name: ";
getline(cin, name); // reads full line incl. spaces
cout << "Hello, " << name << "!\n";
return 0;
}
// compile: g++ program.cpp -o program
- cin >> x stops at whitespace; getline(cin, s) reads the whole line.
- Mixing cin >> with getline needs cin.ignore() to eat the leftover newline.
- References (int& r) are aliases - safer than pointers for parameters.
- const correctness: mark what you don't modify; it prevents bugs and documents intent.
Page 1
From C foundations to OOP, STL, memory and modern C++ - exam and
interview ready
Complete Study Guide | Key Concepts | Examples | Practice Questions
, 1. C++ Basics and I/O
C++ extends C with classes, templates and the STL. It compiles to native code - fast, with manual memory control.
#include <iostream>
#include <string>
using namespace std;
int main() {
string name;
cout << "Enter name: ";
getline(cin, name); // reads full line incl. spaces
cout << "Hello, " << name << "!\n";
return 0;
}
// compile: g++ program.cpp -o program
- cin >> x stops at whitespace; getline(cin, s) reads the whole line.
- Mixing cin >> with getline needs cin.ignore() to eat the leftover newline.
- References (int& r) are aliases - safer than pointers for parameters.
- const correctness: mark what you don't modify; it prevents bugs and documents intent.
Page 1