|
发表于 2003-8-18 08:20:40
|
显示全部楼层
en 我把msdn复制过来
[code:1]
Convert an integer to a string.
char *_itoa(
int value,
char *string,
int radix
);
char *_i64toa(
__int64 value,
char *string,
int radix
);
char * _ui64toa(
unsigned _int64 value,
char *string,
int radix
);
wchar_t * _itow(
int value,
wchar_t *string,
int radix
);
wchar_t * _i64tow(
__int64 value,
wchar_t *string,
int radix
);
wchar_t * _ui64tow(
unsigned __int64 value,
wchar_t *string,
int radix
);
Parameters
value
Number to be converted.
string
String result.
radix
Base of value; must be in the range 2 – 36.
Return Value
Each of these functions returns a pointer to string. There is no error return.
Remarks
The _itoa, _i64toa, and _ui64toa function convert the digits of the given value argument to a null-terminated character string and stores the result (up to 33 characters for _itoa, 65 for _i64toa and _ui64toa) in string. If radix equals 10 and value is negative, the first character of the stored string is the minus sign ( – ). _itow, _i64tow, and _ui64tow are wide-character versions of _itoa, _i64toa, and _ui64toa respectively.
Security Note To prevent buffer overruns, ensure that the string buffer is large enough to hold the converted digits plus the trailing null-character and a sign character.
Generic-Text Routine Mappings
TCHAR.H routine _UNICODE & _MBCS not defined _MBCS defined _UNICODE defined
_itot _itoa _itoa _itow
_i64tot _i64toa _i64toa _i64tow
_ui64tot _ui64toa _ui64toa _ui64tow
Requirements
Routine Required header Compatibility
_itoa <stdlib.h> Win 98, Win Me, Win NT, Win 2000, Win XP
_i64toa <stdlib.h> Win 98, Win Me, Win NT, Win 2000, Win XP
_ui64toa <stdlib.h> Win 98, Win Me, Win NT, Win 2000, Win XP
_itow <stdlib.h> Win 98, Win Me, Win NT, Win 2000, Win XP
_i64tow <stdlib.h> Win 98, Win Me, Win NT, Win 2000, Win XP
_ui64tow <stdlib.h> Win 98, Win Me, Win NT, Win 2000, Win XP
For additional compatibility information, see Compatibility in the Introduction.
Libraries
All versions of the C run-time libraries.
Example
// crt_itoa.c
#include <stdlib.h>
int main( void )
{
char buffer[65];
int r;
for( r=10; r>=2; --r )
{
_itoa( -1, buffer, r );
printf( "base %d: %s (%d chars)\n", r, buffer, strlen(buffer) );
}
printf( "\n" );
for( r=10; r>=2; --r )
{
_i64toa( -1L, buffer, r );
printf( "base %d: %s (%d chars)\n", r, buffer, strlen(buffer) );
}
printf( "\n" );
for( r=10; r>=2; --r )
{
_ui64toa( 0xffffffffffffffffL, buffer, r );
printf( "base %d: %s (%d chars)\n", r, buffer, strlen(buffer) );
}
}
Output
base 10: -1 (2 chars)
base 9: 12068657453 (11 chars)
base 8: 37777777777 (11 chars)
base 7: 211301422353 (12 chars)
base 6: 1550104015503 (13 chars)
base 5: 32244002423140 (14 chars)
base 4: 3333333333333333 (16 chars)
base 3: 102002022201221111210 (21 chars)
base 2: 11111111111111111111111111111111 (32 chars)
base 10: -1 (2 chars)
base 9: 145808576354216723756 (21 chars)
base 8: 1777777777777777777777 (22 chars)
base 7: 45012021522523134134601 (23 chars)
base 6: 3520522010102100444244423 (25 chars)
base 5: 2214220303114400424121122430 (28 chars)
base 4: 33333333333333333333333333333333 (32 chars)
base 3: 11112220022122120101211020120210210211220 (41 chars)
base 2: 1111111111111111111111111111111111111111111111111111111111111111 (64 chars)
base 10: 18446744073709551615 (20 chars)
base 9: 145808576354216723756 (21 chars)
base 8: 1777777777777777777777 (22 chars)
base 7: 45012021522523134134601 (23 chars)
base 6: 3520522010102100444244423 (25 chars)
base 5: 2214220303114400424121122430 (28 chars)
base 4: 33333333333333333333333333333333 (32 chars)
base 3: 11112220022122120101211020120210210211220 (41 chars)
base 2: 1111111111111111111111111111111111111111111111111111111111111111 (64 chars)
[/code:1] |
|