Study
문자 다루기 - <locale>헤더 파일 본문
문자를 다루는 함수는 <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++프로그래밍(책)
'알고리즘 > C++ 개념' 카테고리의 다른 글
STL algorithm - next_permutation (0) | 2021.02.02 |
---|---|
STL algorithm - unique함수를 이용한 문자열 중복제거 (0) | 2021.02.02 |
stack, queue에서 pair 사용 (0) | 2021.01.07 |
String 클래스를 이용한 문자열 사용 (0) | 2021.01.07 |
STL algorithm - sort (0) | 2021.01.07 |