itoa()函数的原型为: char *itoa( int value, char *string,int radix);
itoa()函数有3个参数:第一个参数是要转换的数字,第二个参数是要写入转换结果的目标字符串,第三个参数是转换数字时所用的基数。在例中,转换基数为10。10:十进制;2:二进制…
- itoa()
#include <iostream>//输入输出
#include <stdlib.h>//atoi函数
using namespace std;
const int N = 100010;
void main() {
int a;
cin >> a;
char s[10];
itoa(a, s, 10);
cout << s << endl;
}

错误 C4996 ‘itoa’: The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _itoa. See online help for details
意思是itoa已经被弃用了,替换的方法为_itoa

然后说_itoa不安全,替换使用_itoa_s
所以代码如下:
#include <iostream>//输入输出
#include <stdlib.h>//atoi函数
using namespace std;
const int N = 100010;
void main() {
int a;
cin >> a;
char s[10];
_itoa_s(a, s, 10);
cout << s << endl;
}
举个栗子:
input 10
output 10
参考:
1.atoi() 与 itoa()函数用法
本文探讨了C++中标准库函数itoa的弃用问题,介绍了如何使用安全的_crtversion兼容版本_itoa_s进行整数到字符串的转换,并通过代码示例展示了从输入获取十进制整数并将其转换为字符串的过程。
1万+

被折叠的 条评论
为什么被折叠?



