字符轉(zhuǎn)換為數(shù)字:
#include<stdlib.h>
atoi();將字符轉(zhuǎn)換為整型 例:char ch1;int i=atoi(ch1);
atol();將字符轉(zhuǎn)化為長(zhǎng)整型 例:char ch2;long l=atol(ch2);
atof();將字符轉(zhuǎn)化為浮點(diǎn)型 例:char ch3;float f=atof(ch3);
strtod(); 將字符串轉(zhuǎn)化為雙精度類型 例:string str1;double d=strtod(str1);
strtol(); 將字符串轉(zhuǎn)化為長(zhǎng)整型 例:string str2; long int li=strtol(str2);
strtoul(); 將字符串轉(zhuǎn)化為無(wú)符長(zhǎng)整型 例:sting str3; unsinged long int uli=str(str3);
數(shù)字轉(zhuǎn)換為字符:
itoa(); 將整型轉(zhuǎn)化為字符
例:int i; char ch1; itoa(i,ch1,radix);
radix為基數(shù):想要把ch1轉(zhuǎn)化為十進(jìn)制則為10,八進(jìn)制則為8,十六進(jìn)制則為16
ltoa(); 將長(zhǎng)整型轉(zhuǎn)化為字符 例: long int i li; char ch2; ltoa(li,ch2,radix);
ultoa(); 將無(wú)符長(zhǎng)整型轉(zhuǎn)化為字符 例:unsiged long int uli; char ch3; ultoa(uli,ch3,radix);
字符與字符的轉(zhuǎn)化:
#include<ctype.h>
tolower(); 將一個(gè)大寫(xiě)字母轉(zhuǎn)化為小寫(xiě)字母
例:char upper=C; char lower=tolower(upper);//得lower=c
toupper(); 將一一個(gè)小寫(xiě)字母轉(zhuǎn)化為大寫(xiě)字母
例:char lower=c; char upper=toupper(lower);//得upper=C
新聞熱點(diǎn)
疑難解答
圖片精選