C++ Standard Library C++ STL Library

C++ <cwctype> - towupper() Function



The C++ <cwctype> towupper() function is used to convert the given character to uppercase, if it exists. If the uppercase version of the given wide character does not exist, it remains unchanged.

The following lowercase letters abcdefghijklmnopqrstuvwxyz are replaced with respective uppercase letters ABCDEFGHIJKLMNOPQRSTUVWXYZ.

Syntax

wint_t towupper ( wint_t c );              

Parameters

ch Specify the wide character to be converted, casted to an wint_t, or WEOF.

Return Value

Returns uppercase version of ch or unchanged ch if no uppercase value is listed in the current C locale.

Example:

The example below shows the usage of towupper() function.

#include <iostream>
#include <cwchar>
#include <cwctype>
using namespace std;
 
int main (){
  wchar_t str[50] = L"HELLO World!";

  //converting str into upper case
  int i = 0;
  while(str[i]) {
    str[i] = towupper(str[i]);
    i++;
  }

  //displaying the output
  wcout<<str<<"\n";  
  return 0;
}

The output of the above code will be:

HELLO WORLD!

❮ C++ <cwctype> Library