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

How do I convert a String to an int in Java?

If you look at the Java documentation you’ll notice the “catch” is that this function can throw a NumberFormatException, which of course you have to handle: (This treatment defaults a malformed number to 0, but you can do something else if you like.) Alternatively, you can use an Ints method from the Guava library, which in combination with Java 8’s Optional, makes … Read more