Best way to extract a subvector from a vector?
Suppose I have a std::vector (let’s call it myVec) of size N. What’s the simplest way to construct a new vector consisting of … Read more
Suppose I have a std::vector (let’s call it myVec) of size N. What’s the simplest way to construct a new vector consisting of … Read more
Should I use std::sort(numbers.begin(), numbers.end(), std::greater<int>()); or std::sort(numbers.rbegin(), numbers.rend()); // note: reverse iterators to sort a vector in descending order? Are there any … Read more
Why does the C++ STL not provide any “tree” containers, and what’s the best thing to use instead? I want to store a … Read more
When I do this: std::vector<int> hello; Everything works great. However, when I make it a vector of references instead: std::vector<int &> hello; I … Read more
How do you check that an element is in a set? Is there a simpler equivalent of the following code: myset.find(x) != myset.end() … Read more
Someone brought this article to my attention that claims (I’m paraphrasing) the STL term is misused to refer to the entire C++ Standard … Read more
What is the correct way of iterating over a vector in C++? Consider these two code fragments, this one works fine: for (unsigned … Read more
What is the right way of initializing a static map? Do we need a static function that will initialize it? 12 s 12 … Read more
I’m trying to check if a given key is in a map and somewhat can’t do it: typedef map<string,string>::iterator mi; map<string, string> m; … Read more
I have a std::vector<int>, and I want to delete the n’th element. How do I do that? std::vector<int> vec; vec.push_back(6); vec.push_back(-17); vec.push_back(12); vec.erase(???); … Read more