One-atoi:<stdlib.h>
/*atoi example*/
#include <stdio.h>
#include <stdlib.h>
int main ()
{
int i;
char szInput [256];
printf ("Enter a number: ");
fgets ( szInput, 256, stdin );
i = atoi (szInput);
printf ("The value entered is %d. The double is %d.\n",i,i*2);
return 0;
}
Two-itoa:<stdlib.h>
// itoa example
#include <stdio.h>
#include <stdlib.h>
int main ()
{
int i;
char buffer [33];
printf ("Enter a number: ");
scanf ("%d",&i);
itoa (i,buffer,10);
printf ("decimal: %s\n",buffer);
itoa (i,buffer,16);
printf ("hexadecimal: %s\n",buffer);
itoa (i,buffer,2);
printf ("binary: %s\n",buffer);
return 0;
}
Three-char->string&&string->char:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string x,temp;
char p[15]="i am a boy!";
cin>>x;
cout<<x.c_str()<<endl;
temp=p;
cout<<temp<<endl;
return 0;
}
Four-sprintf(Formatted data to writing a string)<stdio.h>
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
char str[20];
sprintf(str,"%d",168);
cout<<str<<endl;
sprintf(str,"��",123,457);
cout<<"Specified width"<<str<<endl;
sprintf(str,"%8x",123);
cout<<"width+hexadecimal"<<str<<endl;
return 0;
}
Five-ceil(返回大于或者等于指定表达式的最小整数)
// ceil example
#include <stdio.h>
#include <math.h>
int main ()
{
printf ("ceil of 2.3 is %.1lf\n", ceil (2.3) );
printf ("ceil of 3.8 is %.1lf\n", ceil (3.8) );
printf ("ceil of -2.3 is %.1lf\n", ceil (-2.3) );
printf ("ceil of -3.8 is %.1lf\n", ceil (-3.8) );
return 0;
}
Output:
ceil of 2.3 is 3.0
ceil of 3.8 is 4.0
ceil of -2.3 is -2.0
ceil of -3.8 is -3.0