在c++中怎样将整型以字符的类型输出??

如题所述

第1个回答  2011-11-15
itoa是广泛应用的非标准C语言扩展函数。由于它不是标准C语言函数,所以不能在所有的编译器中使用。但是,大多数的编译器(如Windows上的)通常在<stdlib.h>头文件中包含这个函数。在<stdlib.h>中与之有相反功能的函数是atoi。功能:把一整数转换为字符串。

char *itoa(int value, char *string, int radix);

头文件: <stdlib.h>
程序例:   
#include <stdlib.h>
#include <stdio.h>   
int main()   
{   
int number = 123456;   
char string[25];   
itoa(number, string, 10);   
printf("integer = %d string = %s\n", number, string);   
return 0;   
}
第2个回答  2011-11-16
#define N 65 //或者其它的数,也就是该字符在C语言中的ASCⅡ码
#include<stdio.h>
main()
{
int a=N;
printf("%c\n",a); //%c 决定了该输出类型为char类型,也就是字符类型
}
第3个回答  2011-11-15
用sprintf转换 然后输出本回答被网友采纳
第4个回答  2011-11-15
可以用楼上的,也可以直接强制转换为char
第5个回答  2011-11-15
用int 全局声明