std:: tolower
|
헤더 파일에 정의됨
<cctype>
|
||
|
int
tolower
(
int
ch
)
;
|
||
주어진 문자를 현재 설치된 C 로캘에 정의된 문자 변환 규칙에 따라 소문자로 변환합니다.
기본
"C"
로케일에서, 다음 대문자들
ABCDEFGHIJKLMNOPQRSTUVWXYZ
은 해당 소문자들
abcdefghijklmnopqrstuvwxyz
로 대체됩니다.
목차 |
매개변수
| ch | - | 변환될 문자. ch 값이 unsigned char 로 표현 불가능하고 EOF 와 같지 않을 경우, 동작은 정의되지 않음 |
반환값
현재 C 로캘에 소문자 버전이 나열되어 있지 않은 경우 ch 의 소문자 버전 또는 수정되지 않은 ch 입니다.
참고 사항
<cctype>
의 다른 모든 함수들과 마찬가지로,
std::tolower
의 동작은 인자 값이
unsigned
char
로 표현 가능하지도 않고
EOF
와 같지도 않을 경우 정의되지 않습니다. 일반
char
(또는
signed
char
)와 함께 이러한 함수들을 안전하게 사용하려면, 인자를 먼저
unsigned
char
로 변환해야 합니다:
char my_tolower(char ch) { return static_cast<char>(std::tolower(static_cast<unsigned char>(ch))); }
마찬가지로, 반복자의 값 유형이 char 또는 signed char 인 경우 표준 알고리즘과 직접 사용해서는 안 됩니다. 대신 값을 먼저 unsigned char 로 변환하십시오:
std::string str_tolower(std::string s) { std::transform(s.begin(), s.end(), s.begin(), // static_cast<int(*)(int)>(std::tolower) // 잘못됨 // [](int c){ return std::tolower(c); } // 잘못됨 // [](char c){ return std::tolower(c); } // 잘못됨 [](unsigned char c){ return std::tolower(c); } // 올바름 ); return s; }
예제
#include <cctype> #include <clocale> #include <iostream> int main() { unsigned char c = '\xb4'; // ISO-8859-15에서 Ž 문자 // ISO-8859-1에서 ´ (악센트) 문자 std::setlocale(LC_ALL, "en_US.iso88591"); std::cout << std::hex << std::showbase; std::cout << "in iso8859-1, tolower('0xb4') gives " << std::tolower(c) << '\n'; std::setlocale(LC_ALL, "en_US.iso885915"); std::cout << "in iso8859-15, tolower('0xb4') gives " << std::tolower(c) << '\n'; }
가능한 출력:
in iso8859-1, tolower('0xb4') gives 0xb4
in iso8859-15, tolower('0xb4') gives 0xb8
참고 항목
|
문자를 대문자로 변환
(함수) |
|
로캘의
ctype
패싯을 사용하여 문자를 소문자로 변환
(함수 템플릿) |
|
|
와이드 문자를 소문자로 변환
(함수) |
|
|
C 문서
for
tolower
|
|
외부 링크
| 1. | ISO/IEC 8859-1 . 위키백과에서. |
| 2. | ISO/IEC 8859-15 . 위키백과에서. |