Getting Started
C++ Introduction
Discover C++ — the powerful language that adds object-oriented and generic programming to C.
What is C++?
C++ is a general-purpose programming language created by Bjarne Stroustrup as an extension of C. It adds:
- Object-Oriented Programming: Classes, inheritance, polymorphism
- Generic Programming: Templates
- Standard Template Library (STL): Containers, algorithms, iterators
- Modern features: Smart pointers, lambdas, range-based for, modules (C++20)
Why C++?
- Unmatched performance (used in games, trading, browsers, OS)
- Full control over hardware resources
- Massive ecosystem and community
- Used for: game engines (Unreal), browsers (Chrome/Firefox), databases (MySQL), and much more
Hello World in C++
Notice the difference from C:
#include <iostream>instead of#include <stdio.h>std::coutinstead ofprintfusing namespace std;is commonly used (but not always recommended)
Example
cpp
#include <iostream>
#include <string>
int main() {
// Output with cout
std::cout << "Hello, C++!" << std::endl;
// Using namespace std for convenience
using namespace std;
cout << "Using namespace std" << endl;
// Variables
int age = 25;
double pi = 3.14159;
string name = "Alice"; // std::string is much better than char[]
bool isActive = true;
// Modern string formatting
cout << "Name: " << name << ", Age: " << age << endl;
// auto type inference (C++11)
auto count = 42; // int
auto price = 9.99; // double
auto msg = string("Hello");
return 0; // 0 = success
}Try it yourself — CPP