public member function
<locale>

std::ctype::tolower

單個字元 (1)
       char_type tolower (char_type c) const;
序列 (2)
const char_type* tolower (char_type* low, const char_type* high) const;
轉換為小寫
第一個過載 (1) 返回字元 c 的小寫等價字元。如果不存在這樣的小寫等價字元,則返回 c 本身,不作改變。

第二個過載 (2) 將範圍 [low,high) 中的所有大寫字元替換為它們對應的小寫等價字元。

在內部,此函式僅呼叫虛保護成員函式 do_tolower,該函式在通用模板和 char 特化版本 (ctype<char>) 中預設執行上述操作。

存在一個同名的非成員函式 (tolower),其行為與 (1) 相同。

引數

c
要轉換大小寫的字元。
成員型別 char_type 是此 locale facet 的字元型別(定義為 ctype 的模板引數 charT 的別名)。
low, high
指向字元序列的開頭和結尾的指標。使用的範圍是 [low,high),它包含 low 指向的字元到 high 指向的字元之間的所有字元,包括 low 指向的字元,但不包括 high 指向的字元。
請注意,空字元(如果存在)也會被考慮在內,函式將繼續處理它們之後的內容,直到整個範圍被轉換。
成員型別 char_type 是此 locale facet 的字元型別(定義為 ctype 的模板引數 charT 的別名)。

返回值

第一個過載 (1) 返回字元 c 的小寫等價字元(如果不存在這樣的小寫等價字元,則返回 c 本身,不作改變)。

第二個過載始終返回 high

成員型別 char_type 是此 locale facet 的字元型別(定義為 ctype 的模板引數 charT 的別名)。

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// ctype::tolower example
#include <iostream>       // std::cout
#include <locale>         // std::locale, std::ctype, std::use_facet

int main ()
{
  std::locale loc;

  char site[] = "CPlusPlus.com";

  std::cout << "The first letter of " << site << " as a lowercase is: ";
  std::cout << std::use_facet< std::ctype<char> >(loc).tolower ( *site );
  std::cout << '\n';

  std::cout << "The result of converting " << site << " to lowercase is: ";
  std::use_facet< std::ctype<char> >(loc).tolower ( site, site+sizeof(site) );
  std::cout << site << '\n';

  return 0;
}

輸出

The first letter of CPlusPlus.com as a lowercase is: c
The result of converting CPlusPlus.com to lowercase is: cplusplus.com


資料競爭

該物件被訪問。
在 (2) 中,會訪問和修改範圍 [low,high) 中的元素。

異常安全

如果丟擲異常,facet 物件 不會發生任何更改,儘管範圍 (2) 中的字元可能會受到影響。

另見