How can I convert a std::string to int?

In C++11 there are some nice new convert functions from std::string to a number type. So instead of you can use where str is your number as std::string. There are version for all flavours of numbers: long stol(string), float stof(string), double stod(string),… see http://en.cppreference.com/w/cpp/string/basic_string/stol

What is an undefined reference/unresolved external symbol error and how do I fix it?

Compiling a C++ program takes place in several steps, as specified by 2.2 (credits to Keith Thompson for the reference): The precedence among the syntax rules of translation is specified by the following phases [see footnote]. Physical source file characters are mapped, in an implementation-defined manner, to the basic source character set (introducing new-line characters for end-of-line indicators) … Read more

What is the best way to use a HashMap in C++?

The standard library includes the ordered and the unordered map (std::map and std::unordered_map) containers. In an ordered map the elements are sorted by the key, insert and access is in O(log n). Usually the standard library internally uses red black trees for ordered maps. But this is just an implementation detail. In an unordered map insert and access is in … Read more

What is the best way to use a HashMap in C++?

The standard library includes the ordered and the unordered map (std::map and std::unordered_map) containers. In an ordered map the elements are sorted by the key, insert and access is in O(log n). Usually the standard library internally uses red black trees for ordered maps. But this is just an implementation detail. In an unordered map insert and access is in … Read more

How to dynamically allocate arrays in C++

for arrays (which is what you want) or for single elements. But it’s more simple to use vector, or use smartpointers, then you don’t have to worry about memory management. L.data() gives you access to the int[] array buffer and you can L.resize() the vector later. L.get() gives you a pointer to the int[] array.

What does (~0L) mean?

0L is a long integer value with all the bits set to zero – that’s generally the definition of 0. The ~ means to invert all the bits, which leaves you with a long integer with all the bits set to one. In two’s complement arithmetic (which is almost universal) a signed value with all bits set to one is -1. The reason for … Read more