📅  最后修改于: 2023-12-03 15:29:49.583000             🧑  作者: Mango
itoa是C++中的一个字符串函数,作用是将整数转换为字符串。itoa函数是从C语言中继承过来的,它接受三个参数:转换的整数、指向字符数组的指针和进制数。
char* itoa(int value, char* str, int base);
#include <iostream>
#include <cstdlib>
using namespace std;
int main() {
int n = 12345;
char str[10];
itoa(n, str, 10);
cout << "n的字符串表示为:" << str << endl;
return 0;
}
使用itoa函数可以将整数n转换成字符串并存储在字符数组str中,第三个参数10表示转换为十进制。上面的程序运行结果为:
n的字符串表示为:12345