上代码:
// int 转 string
int n = 10;
char num[20] = {
0};
itoa(n, num,10); // 将整型的n转为十进制的字符存储在num中
string str1 = num; // 将 char[] 直接转为string
cout << str1.c_str() << endl;
结束:
分享也是自己对问题再次加深理解的方式,可能不全面,但绝对有用,后面将不断完善~
上代码:
// int 转 string
int n = 10;
char num[20] = {
0};
itoa(n, num,10); // 将整型的n转为十进制的字符存储在num中
string str1 = num; // 将 char[] 直接转为string
cout << str1.c_str() << endl;
结束:
分享也是自己对问题再次加深理解的方式,可能不全面,但绝对有用,后面将不断完善~