Skip to main content

Command Palette

Search for a command to run...

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

Updated
1 min read
Welcome to My C++ Notes: A Beginner's Guide!
S

I am Quantitative Developer, Rust enthusiast and passionate about Algo Trading.

Exercise 1: Find the Maximum Value in a Vector

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";
}

Exercise 2: Remove the last element from the vector

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);
157 views

C++

Part 1 of 3

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.

Up next

The Essential C++ STL Cheat sheet

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...

More from this blog

Untitled Publication

23 posts