DEV Community

Cover image for C++ STL: WHERE HAVE YOU BEEN ALL MY LIFE? 😭
Shruti Shahi for Brain Buffering

Posted on Edited on AI-assisted

C++ STL: WHERE HAVE YOU BEEN ALL MY LIFE? 😭

A little college flashback.

I used to be VERY much on Python's side.

I mean, look at that language. You ask it to do something, and it just does it. No unnecessary drama, no demanding the world from you. Just the bare minimum.

Meanwhile, C and C++ were out here demanding KING TREATMENT for every little thing.

I was genuinely pissed.

Python was my favourite child, and I wasn't even trying to hide it.

And then there was indentation. Python, I love you, but WHY are you having mood swings when I'm already struggling? One misplaced indentation and suddenly we're having problems.

Anyway, fast-forward to college, when I was learning C++ and stumbled upon something called STL.

EXCUSE ME???

YOU MEAN TO TELL ME THIS EXISTS???

All this time I was manually doing things, questioning my life choices, and C++ had THIS hidden somewhere?

Suddenly my ADHD makes me sing Rihanna's Where Have You Been. Coz WHY NOT?

I wasn't cheating on Python. I was simply discovering that C++ had some pretty impressive qualities too. 😭

So, what's STL?

STL = Standard Template Library.

Basically, a collection of ready-made tools in C++ that saves us from implementing everything ourselves.

Three main components:

  • Containers: Store data (vector, list, stack, queue, set, map).
  • Algorithms: Perform operations (sort(), find(), reverse()).
  • Iterators: Help us navigate containers (begin(), end()).

A little example:

#include <bits/stdc++.h>
using namespace std;

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

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

    for (int x : nums)
        cout << x << " ";

    return 0;
}
Enter fullscreen mode Exit fullscreen mode

Output:

1 2 3 5 8
Enter fullscreen mode Exit fullscreen mode

LOOK AT THAT.

One function. Sorted numbers. No manually implementing a sorting algorithm.

And suddenly, C++ wasn't looking so noob anymore.

Maybe I judged you too soon, C++.

Your turn: What's that one programming feature you discovered and immediately thought:

"WHERE HAVE YOU BEEN ALL MY LIFE?"

I need to know. 😭


Brain Buffering 🧠 — Come curious, leave slightly less confused.

Top comments (0)