vc++ 64位长整型转换成字符串

本文介绍了VC++中将64位长整型数值转换为字符串的函数,包括*_itoa、*_i64toa和*_ui64toa等,详细说明了它们的功能、参数及返回值,并提供了安全使用建议和示例代码,适用于Windows多个版本的操作系统。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  Run-Time Library Reference  

_itoa, _i64toa, _ui64toa, _itow, _i64tow, _ui64towSee Also
Data Conversion Routines | _ltoa | _ultoa | Run-Time Routines and .NET Framewo rk Equivalents
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

Fo r additional compatibility info rmation, see Compatibility in the Introduction.

Libraries

All versions of the C run-time libraries.
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 erro r return.

Remarks
The _itoa, _i64toa, and _ui64toa function convert the digits of the given value argument to a null-terminated character string and sto res the result (up to 33 characters fo r _itoa, 65 fo r _i64toa and _ui64toa) in string. If radix equals 10 and value is negative, the first character of the sto red 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

Fo r additional compatibility info rmation, 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;
   fo r( r=10; r>=2; --r )
   {
     _itoa( -1, buffer, r );
     printf( "base %d: %s (%d chars)/n", r, buffer, strlen(buffer) );
   }
   printf( "/n" );
   fo r( r=10; r>=2; --r )
   {
     _i64toa( -1L, buffer, r );
     printf( "base %d: %s (%d chars)/n", r, buffer, strlen(buffer) );
   }
   printf( "/n" );
   fo r( 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)
See Also
Data Conversion Routines | _ltoa | _ultoa | Run-Time Routines and .NET Framewo rk Equivalents



--------------------------------------------------------------------------------

Send feedback on this topic to Microsoft

© Microsoft Co rpo ration. All rights reserved.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值