Top "Stl" questions

The Standard Template Library, or STL, is a C++ library of generic containers, iterators, algorithms, and function objects.

What is the easiest way to initialize a std::vector with hardcoded elements?

I can create an array and initialize it like this: int a[] = {10, 20, 30}; How do I create a std::vector and …

c++ vector stl initialization
How do I erase an element from std::vector<> by index?

I have a std::vector<int>, and I want to delete the n'th element. How do I do …

c++ stl vector erase
Iteration over std::vector: unsigned vs signed index variable

What is the correct way of iterating over a vector in C++? Consider these two code fragments, this one works …

c++ stl unsigned signed
Appending a vector to a vector

Assuming I have 2 standard vectors: vector<int> a; vector<int> b; Let's also say the both …

c++ stl vector
How to find if a given key exists in a C++ std::map

I'm trying to check if a given key is in a map and somewhat can't do it: typedef map<…

c++ dictionary stl
Initializing a static std::map<int, int> in C++

What is the right way of initializing a static map? Do we need a static function that will initialize it?

c++ stl stdmap
Sorting a vector of custom objects

How does one go about sorting a vector containing custom (i.e. user defined) objects. Probably, standard STL algorithm sort …

c++ stl sorting
Determine if map contains a value for a key?

What is the best way to determine if a STL map contains a value for a given key? #include <…

c++ stl map
Remove spaces from std::string in C++

What is the preferred way to remove spaces from a string in C++? I could loop through all the characters …

c++ string stl whitespace