I usually do this to convert string to int:
my_input = int(my_input)
but I was wondering if there was a less clumsy way, because it feels kind of long.
Use Integer.parseInt() to Convert a String to an Integer This method returns the string as a primitive type int. If the string does not contain a valid integer then it will throw a NumberFormatException.
Use the parseInt() function to convert a string to a number, e.g. const num1 = parseInt(str) .
The atoi() function converts a character string to an integer value. The input string is a sequence of characters that can be interpreted as a numeric value of the specified return type.
Atoi is the fastest I could come up with. I compiled with msvc 2010 so it might be possible to combine both templates. In msvc 2010, when I combined templates it made the case where you provide a cb argument slower.
my_input = int(my_input)
There is no shorter way than using the int
function (as you mention)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With