Library functions for converting C + + strings to numbers

Source: Internet
Author: User
Tags terminates

Original link: http://blog.csdn.net/tsinfeng/article/details/58448381, atoi function: Convert a string to an integer
Usage: int atoi (const char *nptr);
Explanation: Atoi is an abbreviation for English array to integer. Atoi () scans the parameter nptr string, if the first character is not a number and is not the sign returns zero, otherwise the type conversion is started, then a non-numeric or terminator/0 stop conversion is detected, and the integer number is returned. Parameter: *nptr: String to convert. return value: Int: The converted number of shapes. Note: The function's header file is "Stdlib.h" 2, Atol function: Convert a string to a long shape usage: Long atol (const char *nptr); verbose explanation: Atol () scans the parameter nptr string, skips the preceding space character, The conversion is not started until a number or sign is encountered, and the conversion is ended with a non-numeric or string end ('/0 '), and the result is returned. Parameter: *nptr: String to convert. Return value: Long: The length of the transformation after the number of shaping. Note: The function's header file is "Stdlib.h" 3, Atof function: Convert a string to double-precision floating-point number usage: Double atof (const char *nptr); verbose: Atof () scans the parameter nptr string, skips the preceding space character, The conversion is not started until a number or sign is encountered, and the conversion is ended with a non-numeric or string end ('/0 '), and the result is returned. The parameter nptr string can contain a positive sign, a decimal point, or E (e) to represent an exponential portion, such as 123.456 or 123e-2. Parameters
  *NPTR: The string to be converted. Return value: Double: the converted dual-precision floating-point number. Note: The function's header file is "Stdlib.h"  4, strtod function: Converts a string to a double-precision floating-point value and reports all remaining numeric usages that cannot be converted: Double strtod (const char *NPTR,CHAR * * ENDPTR); detailed explanation: Strtod () scans the parameter nptr string, skips the preceding space character until it encounters a number or sign to begin the conversion, ends the conversion at the end of a non-numeric or string ('/0 '), and returns the result. If endptr is not null, the character pointer in nptr that terminates with an unqualified condition is returned by ENDPTR. The parameter nptr string can contain a positive sign, a decimal point, or E (e) to represent the exponential portion. such as 123.456 or 123e-2. Parameter:  *nptr: the string to be converted.   **endptr:  If endptr is not null, the character pointer in the nptr that terminates when the condition is encountered is returned by Endptr. Return value: Double: the converted dual-precision floating-point number. Note: The function's header file is "Stdlib.h"  5, Strtol function: Converts a string to a long shape value, and reports all remaining numeric usages that cannot be converted: Long int strtol (const char *nptr,char **endptr, int base); This function converts the parameter nptr string to the number of growth integers based on the parameter base. The parameter base range is from 2 to 36, or 0. The parameter base represents the method used, such as the base value of 10 is used 10, if the base value of 16 is 16 binary. When the base value is 0, the conversion is done in 10, but when a character such as ' 0x ' is used to convert using 16, the ' 0 ' pre-character instead of ' 0x ' will be converted using 8-binary. At first Strtol () scans the parameter nptr string, skips the preceding space character until a number or sign is encountered, and then encounters a non-numeric or string ending ('/0 ') ending the conversion and returning the result. If the parameter endptr is not NULL, the character pointer in nptr that terminates with an unqualified condition is returned by ENDPTR. Parameter:  *nptr: the string to be converted.   **endptr:  If endptr is not null, the character pointer in the nptr that is terminated with the condition is met by ENDPTR is passed back.   Base: The binary return value: Long int: The number of the converted length. Note: The function's header file is "Stdlib.h"  6, Strtoul function: Converts a string to an unsigned long shape value, and reports any remaining digits that cannot be converted. Usage: unsigned long int strtoul (const char *nptr,char **endptr,int base);
Detailed explanation: Strtoul () converts the parameter nptr string to an unsigned long integer based on the parameter base. The parameter base range is from 2 to 36, or 0. The parameter base represents the method used, such as the base value of 10 is used 10, if the base value of 16 is 16 binary number. When the base value is 0, the conversion is made in 10, but encountering a pre-character such as ' 0x ' uses a 16-binary conversion. At first Strtoul () scans the parameter nptr string, skips the preceding space string until a number or sign is encountered, and then encounters a non-numeric or string ending (') ending the conversion and returning the result. If the parameter endptr is not NULL, the character pointer in nptr that terminates with an unqualified condition is returned by ENDPTR.  Parameter: *nptr: String to convert.  **endptr: If endptr is not null, the character pointer in the nptr that is terminated when the condition is encountered is returned by Endptr. Base: Binary return value: unsigned long int: The number of unsigned long shapes converted. Note: The function's header file is "Stdlib.h"

Library functions for converting C + + strings to numbers

Related Article

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.