A Relaxed Look at C++ and the STL: Discovering the Standard Template Library

Hridish GoswamiHridish Goswami
4 min read

Hi! I’m 19, I like building stuff, breaking stuff, and most of all—understanding stuff. When I started learning C++, people kept dropping this term “STL” like it was the cheat code to everything.

At first, I thought STL was something fancy or complex. But guess what? It's just a bunch of tools that make your life easier. And once you get it, it’s like… "Wait, that’s it? I spent 3 hours debugging a custom sort when this already existed?"

So here’s my no-BS, friendly guide to the Standard Template Library (STL) in C++. If you’re just figuring things out like me — this is for you.


🌟 What is STL?

STL = Standard Template Library

Think of it like a really well-organized toolbox. Inside it, you get:

  • Containers (like boxes to store stuff: arrays, lists, stacks…)

  • Algorithms (functions like sort, reverse, find)

  • Iterators (like pointers that help you move through containers)

Basically, it’s a bunch of pre-written code that you can use without reinventing the wheel every time.


📦 STL Containers – Where You Store Stuff

Let’s start with containers, because duh — you gotta put stuff somewhere before you do stuff to it.

1. Vector – The Cooler, Smarter Array

A vector is like a dynamic array that can grow and shrink. Super useful.

#include <iostream>
#include <vector>

int main() {
    std::vector<int> nums = {1, 2, 3};

    nums.push_back(4); // adds 4 at the end
    nums.pop_back();   // removes last element

    for(int i : nums) {
        std::cout << i << " ";
    }

    return 0;
}

🧠 Why it's cool: You don’t have to specify the size beforehand. Just vibe and let it grow.

2. Set – No Duplicates Allowed, Sir

A set stores unique values in sorted order.

#include <iostream>
#include <set>

int main() {
    std::set<int> s;

    s.insert(5);
    s.insert(2);
    s.insert(5); // ignored

    for(int x : s) {
        std::cout << x << " ";
    }

    return 0;
}

🧠 Use this when you want only unique values and don’t want to sort manually.

3. Map – Key-Value Store Like a Mini Dictionary

If you’re from Python-land, this is like a dict.

#include <iostream>
#include <map>

int main() {
    std::map<std::string, int> ages;

    ages["Alice"] = 20;
    ages["Bob"] = 19;

    for(auto pair : ages) {
        std::cout << pair.first << " is " << pair.second << " years old.\n";
    }

    return 0;
}

💡 Perfect when you want to associate keys with values.

⚙️ Algorithms – Do the Work For You

STL also gives you a ton of built-in algorithms that make life easier.

1. Sort It Like It’s Hot

#include <iostream>
#include <vector>
#include <algorithm>

int main() {
    std::vector<int> nums = {5, 2, 8, 1};

    std::sort(nums.begin(), nums.end());

    for(int i : nums)
        std::cout << i << " ";

    return 0;
}

💡 sort() uses quicksort/intro sort internally and is optimized AF.


2. Find Stuff Without Writing Loops

#include <iostream>
#include <vector>
#include <algorithm>

int main() {
    std::vector<int> nums = {10, 20, 30};

    if(std::find(nums.begin(), nums.end(), 20) != nums.end()) {
        std::cout << "Found it!";
    } else {
        std::cout << "Nope.";
    }

    return 0;
}

🔍 Way better than writing that awkward for loop.


🔁 Iterators – Fancy Pointers (kinda)

You can think of iterators as your way of saying:

“Hey, I want to start here and keep going until I say stop.”

Used a lot in algorithms:

std::sort(v.begin(), v.end()); // begin() and end() are iterators

You can also manually iterate like this:

for(auto it = v.begin(); it != v.end(); ++it) {
    std::cout << *it << " ";
}

(But honestly, use range-based for loops unless your college prof insists otherwise lol)


🛠️ STL In Real Life

Let me be real — I used to manually write sorting functions, brute force loops to check duplicates, etc. And then I found out STL had my back this whole time.

In contests, interviews, or college assignments — STL is a massive time-saver. Learn it early, thank yourself later.


🔚 Wrapping Up (TL;DR)

If you scrolled to the end like I sometimes do (no judgment), here’s the gist:

  • STL gives you containers (like vector, set, map), algorithms (like sort, find), and iterators to make coding way easier.

  • Use #include <vector> and all that good stuff.

  • You’re not a lesser dev for using STL — you’re actually smarter for not wasting time.


🌱 My Personal Take

I’m just starting out — I mess up, I Google a lot, I sometimes forget semicolons 😅
But each time I learn something like STL, it makes me feel a bit more in control.

If you’re in that same phase — figuring things out, writing spaghetti code, and trying to make sense of it all — I feel you.

Let’s keep learning. One bug fix at a time.


✍️ Thanks for reading!
If you liked this post or related to the vibe, feel free to drop a comment or follow. I’ll be writing more of these dev-log style posts.

Catch you in the next one 🫶

0
Subscribe to my newsletter

Read articles from Hridish Goswami directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Hridish Goswami
Hridish Goswami