Notice
Recent Posts
Recent Comments
Link
«   2025/07   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

Study

문자 다루기 - <locale>헤더 파일 본문

알고리즘/C++ 개념

문자 다루기 - <locale>헤더 파일

^_^? 2021. 1. 12. 15:00

문자를 다루는 함수는 <locale>헤더 파일에 존재함

toupper(), isalpha(), isdigit()

 

+

isalpha() 내용 추가

알파벳 대문자 "A-Z"는 1을 반환
알파벳 소문자 'a-z"는 2를 반환
알파벳이 아닌것은 0을 반환

 

isalpha(), isdigit()사용 예)

 

string a = "hello";

for(int i=0; i<a.length; i++)

    a[i] = topupper(a[i]); //a가 "HELLO"로 변경

 

cout<< a; // "HELLO"출력

if(isdigit(a[0]) cout <<"숫자";

else if(isalpha(a.at(0)) cout <<"문자"; //a[0]은 문자 'H'

 

 

출력 결과)


HELLO문자

 

 


<참고자료>

https://blockdmask.tistory.com/448

- 명품 c++프로그래밍(책)