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?