String convert int ....

Source: Internet
Author: User

Cstring is often used in CPP programming. For example, the data received from the interface is of the cstring type, but sometimes it accepts numbers but is stored by characters. This requires conversion. The function provided by MS is atio ()

 

Cstring strhour;

Int nhour = atio (char *) (lpctstr) strhour );

 

Verification passed under vs2005 & XP-sp3...

 

The atio () is in the atox. c file.

 

/***
* Atox. C-atoi and atol Conversion
*
* Copyright (c) Microsoft Corporation. All rights reserved.
*
* Purpose:
* Converts a character string into an int or long.
*
**************************************** ***************************************/

# Include <cruntime. h>
# Include <mtdll. h>
# Include <stdlib. h>
# Include <ctype. h>
# Include <mbctype. h>
# Include <tchar. h>
# Include <setlocal. h>
# Ifdef _ MBCS
# UNDEF _ MBCS
# Endif/* _ MBCS */
# Include <tchar. h>

/***
* Long atol (char * nptr)-convert string to long
*
* Purpose:
* Converts ASCII string pointed to by nptr to binary.
* It behaves exactly like strtol (nptr, null, 10 ).
* Please refer to the strtol implementation for details.
*
* Entry:
* Nptr = PTR to string to convert
*
* String format: [whitespace] [sign] [digits]
*
* Exit:
* Good return:
* Result
*
* Overflow return:
* Long_max or long_min
* Errno = erange
*
* No digits or other error condition return:
* 0
*
* Exceptions:
* Input parameters are validated. Refer to the strtox function family.
*
**************************************** ***************************************/

Long _ cdecl _ tstol (
Const _ tchar * nptr
)
{
Return _ tcstol (nptr, null, 10 );
}

Long _ cdecl _ tstol_l (
Const _ tchar * nptr,
_ Locale_t plocinfo
)
{
Return _ tcstol_l (nptr, null, 10, plocinfo );
}

/***
* Int atoi (char * nptr)-convert string to int
*
* Purpose:
* Converts ASCII string pointed to by nptr to binary.
* It behaves exactly like (INT) strtol (nptr, null, 10 ).
* Please refer to the strtol implementation for details.
*
* Entry:
* Nptr = PTR to string to convert
*
* Exit:
* Good return:
* Result
*
* Overflow return:
* Int_max or int_min
* Errno = erange
*
* No digits or other error condition return:
* 0
*
* Exceptions:
* Input parameters are validated. Refer to the strtox function family.
*
**************************************** ***************************************/

Int _ cdecl _ tstoi (
Const _ tchar * nptr
)
{
Return (INT) _ tstol (nptr );
}

Int _ cdecl _ tstoi_l (
Const _ tchar * nptr,
_ Locale_t plocinfo
)
{
Return (INT) _ tstol_l (nptr, plocinfo );
}

# Ifndef _ no_int64

/***
* Int atoi64 (char * nptr)-convert string to int64
*
* Purpose:
* Converts ASCII string pointed to by nptr to binary.
* It behaves exactly like (INT) strtoi64 (nptr, null, 10 ).
* Please refer to the strtoi64 implementation for details.
*
* Entry:
* Nptr = PTR to string to convert
*
* Exit:
* Good return:
* Result
*
* Overflow return:
* _ I64_max or _ i64_min
* Errno = erange
*
* No digits or other error condition return:
* 0
*
* Exceptions:
* Input parameters are validated. Refer to the strtox function family.
*
**************************************** ***************************************/

_ Int64 _ cdecl _ tstoi64 (
Const _ tchar * nptr
)
{
Return _ tcstoi64 (nptr, null, 10 );
}

_ Int64 _ cdecl _ tstoi64_l (
Const _ tchar * nptr,
_ Locale_t plocinfo
)
{
Return _ tcstoi64_l (nptr, null, 10, plocinfo );
}

# Endif/* _ no_int64 */

 

The interesting question is, why is the name atio?

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.