Localization library | |||||||||||||||||||||||||
Regular expressions library(C++11) | |||||||||||||||||||||||||
Formatting library(C++20) | |||||||||||||||||||||||||
Null-terminated sequence utilities | |||||||||||||||||||||||||
Byte strings | |||||||||||||||||||||||||
Multibyte strings | |||||||||||||||||||||||||
Wide strings | |||||||||||||||||||||||||
Primitive numeric conversions | |||||||||||||||||||||||||
| |||||||||||||||||||||||||
Text encoding identifications | |||||||||||||||||||||||||
|
Functions | ||||||||||||||||||||||||||||||||||||
Character classification | ||||||||||||||||||||||||||||||||||||
Character manipulation | ||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||
Conversions to numeric formats | ||||||||||||||||||||||||||||||||||||
|
| |||||||||||||||||||||||||||||||||||
String manipulation | ||||||||||||||||||||||||||||||||||||
String examination | ||||||||||||||||||||||||||||||||||||
Character array functions | ||||||||||||||||||||||||||||||||||||
Miscellaneous | ||||||||||||||||||||||||||||||||||||
Defined in header <cctype> | ||
int tolower(int ch); | ||
Converts the given character to lowercase according to the character conversion rules defined by the currently installed C locale.
In the default"C" locale, the following uppercase lettersABCDEFGHIJKLMNOPQRSTUVWXYZ
are replaced with respective lowercase lettersabcdefghijklmnopqrstuvwxyz
.
Contents |
ch | - | character to be converted. If the value ofch is not representable asunsignedchar and does not equalEOF, the behavior is undefined |
Lowercase version ofch or unmodifiedch if no lowercase version is listed in the current C locale.
Like all other functions from<cctype>, the behavior ofstd::tolower
is undefined if the argument's value is neither representable asunsignedchar nor equal toEOF. To use these functions safely with plainchars (orsignedchars), the argument should first be converted tounsignedchar:
char my_tolower(char ch){returnstatic_cast<char>(std::tolower(static_cast<unsignedchar>(ch)));}
Similarly, they should not be directly used with standard algorithms when the iterator's value type ischar orsignedchar. Instead, convert the value tounsignedchar first:
std::string str_tolower(std::string s){std::transform(s.begin(), s.end(), s.begin(),// static_cast<int(*)(int)>(std::tolower) // wrong// [](int c){ return std::tolower(c); } // wrong// [](char c){ return std::tolower(c); } // wrong[](unsignedchar c){return std::tolower(c);}// correct);return s;}
#include <cctype>#include <clocale>#include <iostream> int main(){unsignedchar c='\xb4';// the character Ž in ISO-8859-15// but ´ (acute accent) in 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';}
Possible output:
in iso8859-1, tolower('0xb4') gives 0xb4in iso8859-15, tolower('0xb4') gives 0xb8
converts a character to uppercase (function)[edit] | |
converts a character to lowercase using thectype facet of a locale(function template)[edit] | |
converts a wide character to lowercase (function)[edit] | |
C documentation fortolower |
1. | ISO/IEC 8859-1. From Wikipedia. |
2. | ISO/IEC 8859-15. From Wikipedia. |