stoi function

Disclaimer: This article is a blogger original article, For reprint please contact the bloggers. https://blog.csdn.net/GregoryHanson/article/details/85954943

Recent practice type conversion functions used. Matlab previously used type conversion functions are xx2xx, just use these functions c ++, and are not familiar with, so there has been a problem that bothers me most of the day, has been submitted RE, finally found the reason.

text:

The official document reference page:

http://www.cplusplus.com/reference/string/stoi/

head File:

#include<string>

Similar functions:
STOL like: the string into other types
atoi like: string does not accept as input parameters for the string into char *. Meanwhile, without atoi range checking type upper limit / lower bound directly output when the / lower bound.

note! ! !

stoi function will do range checking, if required converting the digital int beyond the range that is beyond [-2147483648,2147483648], there will be Runtime Error! ! !
Therefore, when the title input character string length greater than or equal 10, you must pay attention!
One possible solution is to use stoll function instead stoi, the string is converted to long long int.

Guess you like

Origin blog.csdn.net/GregoryHanson/article/details/85954943