Main Function
int main() {
return 0;
}The entry point of a C++ program.
C++ syntax quick reference: streams, vectors, classes, smart pointers and templates, based on cppreference. Every item below is clearly marked as a shortcut, command, or syntax reference.
int main() {
return 0;
}The entry point of a C++ program.
std::cout << "Hello" << std::endl;Prints to standard output.
std::vector<int> v = {1, 2, 3};
v.push_back(4);Creates a resizable array.
for (const auto& x : v) {
...
}Loops over every element.
#include <iostream>
#include <vector>Includes a standard header.
auto total = 0.0;Lets the compiler deduce the type.
for (int i = 0; i < n; ++i) {
...
}Loops a set number of times.
std::string s = "hi";
s += "!";
s.size();Works with text strings.
The entry point of a C++ program.
int main() {
return 0;
}Prints to standard output.
std::cout << "Hello" << std::endl;Creates a resizable array.
std::vector<int> v = {1, 2, 3};
v.push_back(4);Loops over every element.
for (const auto& x : v) {
...
}Includes a standard header.
#include <iostream>
#include <vector>Lets the compiler deduce the type.
auto total = 0.0;Loops a set number of times.
for (int i = 0; i < n; ++i) {
...
}Works with text strings.
std::string s = "hi";
s += "!";
s.size();Defines a class with a constructor.
class Dog {
public:
explicit Dog(std::string n) : name(std::move(n)) {}
private:
std::string name;
};Lets a function modify the caller's variable.
void inc(int& n) { ++n; }Writes an inline anonymous function.
auto add = [](int a, int b) { return a + b; };Sorts elements in place.
std::sort(v.begin(), v.end());Compiles with a modern standard.
g++ -std=c++20 main.cpp -o mainReads from standard input.
std::cin >> n;Creates sorted key-value pairs.
std::map<std::string, int> ages;
ages["Ada"] = 36;Owns heap memory automatically.
auto p = std::make_unique<Dog>("Rex");Writes a function for any type.
template <typename T>
T maxOf(T a, T b) { return a > b ? a : b; }Handles exceptions.
try {
...
} catch (const std::exception& e) {
std::cerr << e.what();
}Shares ownership of heap memory.
auto p = std::make_shared<Dog>("Rex");Groups names to avoid clashes.
namespace app {
int version = 1;
}It covers 20 common C++ patterns and examples, including Main Function, Print to Console, Create a Vector, Range-Based For Loop, Include a Header.
Yes. Each reference page includes a copyable code example.
Check the linked documentation for language or runtime version requirements. Libraries, file paths, terminal quoting and environment settings can differ across systems; no blanket platform compatibility is implied.