函数原形
char *itoa(int value, char *string, int radix)
将整形数value转换为其等价的字符串
头文件stdlib.h
Parameters(参数说明)
第一个参数:valueNumber to be converted(将要被转换的值)
第二个参数:stringString result(转换的结果)
第三个参数:radixBase of value; must be in the range 2 –36(转换的基数,取值范围2-36。例如radix=10表示10进制,radix=8表示8进制。)
返回值:与string参数相同,便于函数的嵌套调用
例子:(来自MSDN,有删改)
- #include
#include #includecpp代码voidmain(void)
- {
- charbuffer[20];
- inti=3445;
- itoa(i,buffer,10);
- printf("Stringofinteger%d(radix10):%sn",i,buffer);
- itoa(i,buffer,16);
- printf("Stringofinteger%d(radix16):0x%sn",i,buffer);
- itoa(i,buffer,2);
- printf("Stringofinteger%d(radix2):%sn",i,buffer);
- system("pause");
- }
void main( void ){ char buffer[20]; int i = 3445; itoa( i, buffer, 10 ); printf( "String of integer %d (radix 10): %sn", i, buffer ); itoa( i, buffer, 16 ); printf( "String of integer %d (radix 16): 0x%sn", i, buffer ); itoa( i, buffer, 2 ); printf( "String of integer %d (radix 2): %sn", i, buffer ); system("pause");}Cpp代码inta=10;
- CStringstr;
- str.Format("a=%d",a);
int a = 10; CString str;str.Format("a=%d",a);
函数原型:int sprintf(char*buffer,const char*format [, argument] ... );
举例说明:
- inta=10;
- sprintf(buffer;"size=%d";a);