天天看點

ctype.h頭檔案的一些函數說明

1.isalpha

isalpha()用來判斷一個字元是否為字母,如果是字元則傳回非零,否則傳回零。

cout << isalpha('a');//傳回非零
	cout << isalpha('2');//傳回0
           

2.isalnum

isalnum()用來判斷一個字元是否為數字或者字母,也就是說判斷一個字元是否屬于a~z||A~Z||0~9。

cout << isalnum('a');//輸出非零
	cout << isalnum('2');//非零
	cout << isalnum('.');//零
           

3.islower

islower()用來判斷一個字元是否為小寫字母,也就是是否屬于a~z。

cout << islower('a');//非零
	cout << islower('2');//輸出0
	cout << islower('A');//輸出0
           

4.isupper

isupper()和islower相反,用來判斷一個字元是否為大寫字母。

cout << isupper('a');//傳回0
	cout << isupper('2');//傳回0
	cout << isupper('A');//傳回非零
           

5.isblank

isblank()用來判斷一個字元是否為空格。

cout << isblank('');//非零
	cout << islower('2');//輸出0	
           

類似的還有 isalpha()(判斷字元是否為26個字母中的一個,不區分大小寫),iscntrl(int c)(檢查字元是否是控制字元),isdigit(int c)(檢查字元是否為十進制數字字元0~9)等等。 關于以上函數可參考:http://www.cplusplus.com/reference/cctype/isblank/

關于ctype.h中的函數參數為何都是int類型的說明,可參考:http://c.biancheng.net/ref/4.html <\front>

1.isalpha

isalpha()用來判斷一個字元是否為字母,如果是字元則傳回非零,否則傳回零。

cout << isalpha('a');//傳回非零
	cout << isalpha('2');//傳回0
           

2.isalnum

isalnum()用來判斷一個字元是否為數字或者字母,也就是說判斷一個字元是否屬于a~z||A~Z||0~9。

cout << isalnum('a');//輸出非零
	cout << isalnum('2');//非零
	cout << isalnum('.');//零
           

3.islower

islower()用來判斷一個字元是否為小寫字母,也就是是否屬于a~z。

cout << islower('a');//非零
	cout << islower('2');//輸出0
	cout << islower('A');//輸出0
           

4.isupper

isupper()和islower相反,用來判斷一個字元是否為大寫字母。

cout << isupper('a');//傳回0
	cout << isupper('2');//傳回0
	cout << isupper('A');//傳回非零
           

5.isblank

isblank()用來判斷一個字元是否為空格。

cout << isblank('');//非零
	cout << islower('2');//輸出0	
           

類似的還有 isalpha()(判斷字元是否為26個字母中的一個,不區分大小寫),iscntrl(int c)(檢查字元是否是控制字元),isdigit(int c)(檢查字元是否為十進制數字字元0~9)等等。 關于以上函數可參考:http://www.cplusplus.com/reference/cctype/isblank/

關于ctype.h中的函數參數為何都是int類型的說明,可參考:http://c.biancheng.net/ref/4.html <\front>

c++

繼續閱讀