public member function
<locale>

std::ctype::toupper

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

第二個過載 (2) 將範圍 [low,high) 內的任何小寫字元替換為其大寫等效字元。

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

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

引數

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

返回值

第一個過載 (1) 返回 c 的大寫等效字元(如果不存在則返回 c 本身,不作修改)。

第二個過載始終返回 high

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

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// ctype::toupper 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 an uppercase is: ";
  std::cout << std::use_facet< std::ctype<char> >(loc).toupper(*site);
  std::cout << '\n';

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

  return 0;
}

輸出

The first letter of cplusplus.com as an uppercase is: C
The result of converting cplusplus.com to uppercase is: CPLUSPLUS.COM


資料競爭

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

異常安全

如果發生異常,facet 物件不會有任何改變,但範圍 (2) 中的字元可能會受到影響。

另見