Relative Content

Tag Archive for c++stl

Issue with the STL in C++ cmath

I was compiling the code and found out an issue with the cmath library. I dont know what is wrong it was like ‘x+=pow(n%10,3)’, where the answer should be 152 but it shows 151 This happned while solving the armstrong number problem…

Unable to initialize the size of a vector using scientific notation in C++

I was trying to solve a question on leetcode Count primes, where we need to check whether a number is prime, for all numbers less than a given number. The easiest way I knew was to precompute a boolean vector using the sieve of Eratosthenes containing true if the number is prime, and false if it isn’t.

std::map/std::set and equal_range, what’s the reasoning here?

I just noticed that std::map and std::set have the member function equal_range returning an iterator range of values for a certain key. How does this make sense when a map and a set are always ordered key/value (as in a single key for a single value, or both combined) containers.