function template
<locale>

std::toupper

template <class charT>  charT toupper (charT c, const locale& loc);
使用 locale 將小寫字母轉換為大寫字母
該函式根據 locale 的 ctype facet,將引數 c 轉換為其大寫等效項(如果 c 是小寫字母且具有大寫等效項)。如果無法進行此類轉換,則返回 c 不變。

此函式返回的結果與呼叫 ctype::toupper 相同,如下所示:

1
use_facet < ctype<charT> > (loc).toupper (c)

此函式模板過載了 C 函式 toupper(定義在 <cctype> 中)。

引數

c
要轉換的字元。
loc
要使用的 locale。它必須具有 ctype 方面。

模板引數 charT 是字元型別。

返回值

如果存在,則為 c 的大寫等效項。否則為 c 不變。

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
// toupper example (C++)
#include <iostream>       // std::cout
#include <string>         // std::string
#include <locale>         // std::locale, std::toupper

int main ()
{
  std::locale loc;
  std::string str="Test String.\n";
  for (std::string::size_type i=0; i<str.length(); ++i)
    std::cout << std::toupper(str[i],loc);
  return 0;
}

輸出

TEST STRING.


資料競爭

將訪問 loc 及其 ctype 方面。

異常安全

強保證:如果丟擲異常,則沒有效果。

另見