c++整型->字符型转换

时间:2021-09-21 15:58:11

有itoa(),atoi(),sprintf()三个函数

使用字符串流:

 #include<iostream>
#include<string>
#include<sstream>
using namespace std;
string itos(int i) // 将int 转换成string{
{
stringstream s;
s << i;
return s.str();
}
int main() {
int i = ;
string ss = itos(i);
const char* p = ss.c_str();
cout << ss << " " << p << "\n";
}

itoa()函数

 #include<iostream>
using namespace std;
int main()
{
int number = ;
char string[];
_itoa_s(number, string, );
cout << string << endl;
return ;
}