c語言標準庫中字符轉(zhuǎn)換函數(shù)和數(shù)字轉(zhuǎn)換函數(shù)
字符轉(zhuǎn)換為數(shù)字:
#include<stdlib.h>
atoi();將字符轉(zhuǎn)換為整型 例:char ch1;int i=atoi(ch1);
atol();將字符轉(zhuǎn)化為長整型 例:char ch2;long l=atol(ch2);
atof();將字符轉(zhuǎn)化為浮點型 例:char ch3;float f=atof(ch3);
strtod(); 將字符串轉(zhuǎn)化為雙精度類型 例:string str1;double d=strtod(str1);
strtol(); 將字符串轉(zhuǎn)化為長整型 例:string str2; long int li=strtol(str2);
strtoul(); 將字符串轉(zhuǎn)化為無符長整型 例: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)化為十進制則為10,八進制則為8,十六進制則為16
ltoa(); 將長整型轉(zhuǎn)化為字符 例: long int i li; char ch2; ltoa(li,ch2,radix);
ultoa(); 將無符長整型轉(zhuǎn)化為字符 例:unsiged long int uli; char ch3; ultoa(uli,ch3,radix);
字符與字符的轉(zhuǎn)化:
#include<ctype.h>
tolower(); 將一個大寫字母轉(zhuǎn)化為小寫字母
例:char upper=C; char lower=tolower(upper);//得lower=c
toupper(); 將一一個小寫字母轉(zhuǎn)化為大寫字母
例:char lower=c; char upper=toupper(lower);//得upper=C
相關文章
C++中類的成員函數(shù)及內(nèi)聯(lián)函數(shù)使用及說明
這篇文章主要介紹了C++中類的成員函數(shù)及內(nèi)聯(lián)函數(shù)使用及說明,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-11-11