有itoa(),atoi(),sprintf()三个函数
使用字符串流:
1 #include<iostream> 2 #include<string> 3 #include<sstream> 4 using namespace std; 5 string itos(int i) // 将int 转换成string{ 6 { 7 stringstream s; 8 s << i; 9 return s.str(); 10 } 11 int main() { 12 int i = 127; 13 string ss = itos(i); 14 const char* p = ss.c_str(); 15 cout << ss << " " << p << " "; 16 }
itoa()函数
1 #include<iostream> 2 using namespace std; 3 int main() 4 { 5 int number = 12345; 6 char string[32]; 7 _itoa_s(number, string, 10); 8 cout << string << endl; 9 return 0; 10 }