itoa , atoi ,sprintf 的用法

来源:互联网 发布:淘宝怎么卖眼药水 编辑:程序博客网 时间:2024/05/21 06:55
#include<cstdio>#include<iostream>#include<cstdlib>#include<windows.h>#define NN 4294967040using namespace std;int main(){     /* itoa(int,char[],n)   --> 把int化为n进制  transfer to  char[]*/     int a=127;char b[1000];itoa(a,b,2);int i=0;    while(1)     {     if(b[i]=='\0') break; else cout<<b[i]; i++;     }      //输出为 1111111    cout<<endl;  /* sprintf(char[],"格式控制符",int)   --> 把int化为n进制  transfer to  char[]*/    char c[1000];sprintf(c,"%x",a);i=0;while(1)     {     if(c[i]=='\0') break; else cout<<c[i]; i++;     }         //输出为 7f   /* (int) atoi(char[])   --> char[]  transfer to int  */  int d;d=atoi(b);cout<<endl<<d; //输出为 1111111d=atoi(c);cout<<endl<<d; //输出为 7 (注意区别:转换到第一个非“数字(的字符)”) } 

0 0