C++ Syntax References

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.

Most Useful C++ Syntax References

C++Syntax

Main Function

Code example
int main() { return 0; }

The entry point of a C++ program.

Learn More
C++Syntax

Print to Console

Code example
std::cout << "Hello" << std::endl;

Prints to standard output.

Learn More
C++Syntax

Create a Vector

Code example
std::vector<int> v = {1, 2, 3}; v.push_back(4);

Creates a resizable array.

Learn More
C++Syntax

Range-Based For Loop

Code example
for (const auto& x : v) { ... }

Loops over every element.

Learn More
C++Syntax

Include a Header

Code example
#include <iostream> #include <vector>

Includes a standard header.

Learn More
C++Syntax

Auto Type Deduction

Code example
auto total = 0.0;

Lets the compiler deduce the type.

Learn More
C++Syntax

Classic For Loop

Code example
for (int i = 0; i < n; ++i) { ... }

Loops a set number of times.

Learn More
C++Syntax

Use std::string

Code example
std::string s = "hi"; s += "!"; s.size();

Works with text strings.

Learn More

More C++ Syntax References

Frequently Asked Questions

What does this C++ syntax reference cover?

It covers 20 common C++ patterns and examples, including Main Function, Print to Console, Create a Vector, Range-Based For Loop, Include a Header.

Can I copy the C++ examples?

Yes. Each reference page includes a copyable code example.

What affects these C++ examples?

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.