The C ++ standard library string processes two functions: isdigit () and isxdigit ()

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.