C++实现进制转换

Linux内核中只有atoi()函数,被包含在stdlib.h头文件中,而没有itoa()函数,不过,itoa()函数的功能可以用sprintf()函数代替。

//10 --> 8:
char s[100] = {0};  
sprintf(s, "%o", 15); 
cout<<s<<endl; //17

//8--> 10:
char str[100] = "17";  
 int i = 0;  
sscanf(str, "%x", &i); //15

//10 --> 16:
char s[100] = {0};  
sprintf(s, "%x", 15); 
cout<<s<<endl; //f

//16 --> 10:
char str[100] = "f";  
 int i = 0;  
sscanf(str, "%x", &i); //15

//10 --> 10(转为字符串):
char s[100] = {0};  
sprintf(s, "%d", 15); 
cout<<s<<endl; //15
原文地址:https://www.cnblogs.com/xiaocai-ios/p/7779761.html