반응형
1. 대문자 / 소문자 판별
1. isupper
int isupper(int ch);
- ch가 대문자 알파벳(A~Z)이면 0이 아닌 값(true)을 반환
- 아니면 0(false) 반환
2. islower
int islower(int ch);
- ch가 소문자 알파벳(a~z)이면 0이 아닌 값(true) 반환
- 아니면 0(false) 반환
#include <iostream>
#include <cctype>
using namespace std;
int main() {
char a = 'A', b = 'z', c = '1';
cout << isupper(a) << endl; // 1 (true)
cout << isupper(b) << endl; // 0
cout << islower(b) << endl; // 1 (true)
cout << islower(c) << endl; // 0
}
2. 대문자 / 소문자 변환
1. toupper
int toupper(int ch);
- 소문자면 대문자로 변환된 값 반환
- 그 외 문자는 변화 없이 그대로 반환
2. tolower
int tolower(int ch);
- 대문자면 소문자로 변환된 값 반환
- 그 외 문자는 변화 없음
#include <iostream>
#include <cctype>
using namespace std;
int main() {
char lower = 'h';
char upper = 'Q';
char digit = '5';
cout << (char)toupper(lower) << endl; // H
cout << (char)tolower(upper) << endl; // q
cout << (char)tolower(digit) << endl; // 5 (변화 없음)
}
※ toupper, tolower 모두 반환값이 int 형 정수이기 때문에 무조건 형변환을 시켜야 제대로 출력이 된다
반응형
'프로그래밍 언어 > C++' 카테고리의 다른 글
| C++ stoi 사용법 정리 (0) | 2025.09.30 |
|---|---|
| C++ 숫자 / 알파벳 / 공백 / 특수문자 판별 함수 정리 (isalpha, isdigit, isalnum, isspace, ispunct) (0) | 2025.09.30 |
| C++ string::npos (-1) find함수의 반환값 (0) | 2025.09.29 |
| C++ String 헤더의 substr / find / erase 사용법 (0) | 2025.09.29 |
| C++에서 NULL , NUL, 0, \0 의 차이 (0) | 2025.09.27 |
댓글