We often need to convert the string type to the int, long, double, and float types. The cctype header file provides the verification functions isdigit () and isxdigit () before conversion (). Through vs2010 experiment:
Main () {std: strDigit = ""; std: strXDigit = ""; * szDigit = ""; * szXDigit = ""; std :: locale loc (""); (isdigit (* szDigit) {std: cout <szDigit <"" ;}( isdigit (* (strDigit. c_str () {std: cout <strDigit <"" ;}( isxdigit (* szXDigit) {std :: cout <szXDigit <";} (isxdigit (* (strXDigit. c_str () {std: cout <strXDigit <"";} 0 ;}
Program output:
123.35 is digit.
456.123 is digit.
0x56 is hex.
0x57 is hex.
If you do not use * szDigit, * szXDigit, * (strDigit. c_str (), * (strXDigit. instead, use szDigit, szXDigit, and strDigit. c_str (), strXDigit. c_str () cannot be compiled successfully.
The locale header file needs to be referenced in vc2012. The usage is
Std: locale loc ("");
Isdigit (* szDigit, loc );
However, you can use szDigit to compile the code, but the result is not correct.