I started learning about something called STL (Standard Template Library) in C++. Honestly, I have no idea how it works, but people say it’s important, so I tried learning it.
Map : Confusing
I think it’s for storing stuff with keys and values, but honestly, it just made things more confusing. But why do we even need a map? Can’t we just use two arrays—one for keys and one for values? Seems simpler to me. Also, wikipedia said you can check if a key exists with find, but when I tried it, I got all sorts of errors.
Set : What even is this
So then I looked at set. wiki said it’s for storing unique things, but I thought arrays already do that? Anyway, here’s what I wrote:
The output was 10 20. Cool, I guess? But I don’t get why it ignored the duplicate. What if I want duplicates? Also, wiki said it’s sorted automatically, but it’s not like I needed it sorted here.
valarray : Why is this a thing ?
While exploring STL, I stumbled upon something called valarray. From what I read, it’s supposed to be useful for mathematical operations on arrays, but I have no idea why anyone would use it.
The output was 2 4 6 8, which is kind of neat, I guess? But I don’t see why you’d use this instead of just writing a loop to multiply everything. Also, it has other weird operations like slicing and shifting, which sound cool but are way over my head. Does anyone actually use valarray in real problems? It feels like one of those features that’s there just to look fancy.
What I Learned (or Didn’t)
- STL has a lot of stuff, but I’m not sure why it’s better than normal code.
- Maps seem unnecessary unless you’re doing something weird.
- Sets are okay if you hate duplicates, I guess.
- valarray is confusing and maybe for mathematicians?
Help me
can someone explain why STL is such a big deal? I feel like I’m missing something obvious here. Also, if you have any tips, drop them in the comments. I’m clearly struggling, and any help would be awesome.
Thanks!