Skip to content

Latest commit

 

History

History
54 lines (43 loc) · 1.11 KB

File metadata and controls

54 lines (43 loc) · 1.11 KB

toupper

  • cctype[meta header]
  • std[meta namespace]
  • function[meta id-type]
namespace std {
  int toupper(int ch);
}

概要

ch を大文字に変換する(変換はロケールの影響を受ける)。

戻り値

ch に大文字があれば、大文字化した ch。大文字がなければ ch

#include <cctype>
#include <iostream>

int main() {
    std::cout << "toupper('A') = " << static_cast<char>(std::toupper('A')) << std::endl
              << "toupper('a') = " << static_cast<char>(std::toupper('a')) << std::endl
              << "toupper('1') = " << static_cast<char>(std::toupper('1')) << std::endl
              << "toupper('.') = " << static_cast<char>(std::toupper('.')) << std::endl
              << "toupper('$') = " << static_cast<char>(std::toupper('$')) << std::endl;
}
  • std::toupper[color ff0000]

出力例

toupper('A') = A
toupper('a') = A
toupper('1') = 1
toupper('.') = .
toupper('$') = $

実装例(ASCII互換文字コードの場合)

int toupper(int ch) {
  if (islower(ch)) {
    ch ^= 32;
  }
  return ch;
}