Welcome to My C++ Notes: A Beginner's Guide!

Search for a command to run...

No comments yet. Be the first to comment.
This series uncovers basic concepts, some lesser-known features, and advanced techniques in C++. From Smart pointers basics to STL nuances and performance optimization, each post provides practical insights for both newcomers and seasoned developers.
This cheat sheet provides a quick reference to the most commonly used operations and features of std::vector in C++. Vectors Vectors are a part of the C++ Standard Template Library (STL) and are one of the most commonly used sequence containers. They...
Iterators are a fundamental concept in programming that enable you to process a sequence of items, such as elements in a collection, one at a time, without revealing the collection's internal structure. They form the backbone of operations like loopi...

A closure is an anonymous function that can capture variables from its environment. At a high level, Rust closures allow you to write small, concise functions inline, without having to formally define a new fn with a name. They’re particularly handy ...

Immutability is a cool concept in programming that C++ questions with "why?" It means that once you create a variable or object, you can't change its state. This idea somewhat opposes object-oriented concepts, yet it's crucial for writing clean, main...

Object-oriented programming, also called OOP, is a programming style that is dependent on the concept of objects. It is very popular and established. It is like designing and organizing your code by thinking of parts of your program as real-world obj...

Traits are the most important topic to understand the design patterns in Rust. Traits are fundamental feature in Rust that provide a way for shared behavior, abstraction and polymorphish. You can think of traits as interfaces in other programming la...

std::vector<int> vec = {10, 20, 5, 30, 15};
auto max_iter = std::max_element(vec.begin(), vec.end());
if (max_iter != vec.end()) {
std::cout << "The maximum value is " << *max_iter << "\n";
} else {
std::cout << "The vector is empty.\n";
}
To retrieve and remove the last element of a std::vector in C++, you can use a combination of the back() and pop_back() member functions. Alternatively using Iterators, you can use end and erase although this approach is less efficient for removing than pop_back();
int lastElement = vec.back(); // Get the last element 15
vec.pop_back(); // // Remove 15
auto it = vec.end() - 1;
int lastElement = *it;
myVector.erase(it);