Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::tolower

      From cppreference.com
      <cpp‎ |string‎ |byte
       
       
       
       
      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

      [edit]Parameters

      ch - character to be converted. If the value ofch is not representable asunsignedchar and does not equalEOF, the behavior is undefined

      [edit]Return value

      Lowercase version ofch or unmodifiedch if no lowercase version is listed in the current C locale.

      [edit]Notes

      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;}

      [edit]Example

      Run this code
      #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

      [edit]See also

      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

      [edit]External links

      1. ISO/IEC 8859-1. From Wikipedia.
      2. ISO/IEC 8859-15. From Wikipedia.
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/string/byte/tolower&oldid=178558"

      [8]ページ先頭

      ©2009-2025 Movatter.jp