C++ Standard Library C++ STL Library

C++ <cctype> - toupper() Function



The C++ <cctype> toupper() function is used to convert the given character to uppercase according to the character conversion rules defined by the currently installed C locale.

In the default "C" locale, the following lowercase letters abcdefghijklmnopqrstuvwxyz are replaced with respective uppercase letters ABCDEFGHIJKLMNOPQRSTUVWXYZ.

Syntax

int toupper ( int ch );               

Parameters

ch Specify the character to be converted, casted to an int, or EOF.

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 toupper() function.

#include <iostream>
#include <cctype>
using namespace std;
 
int main (){
  char str[50] = "HELLO World!";

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

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

The output of the above code will be:

HELLO WORLD!

❮ C++ <cctype> Library