C++ cctype toupper() Function
Example
Convert a character to uppercase:
char lower = 'a';
char upper = toupper(lower);
cout << lower << " in uppercase is " << upper;
Definition and Usage
The toupper() function returns the uppercase version of a character. If the character is not a lowercase letter, like '5' or '!', it is returned without any change.
The function returns an int, so store the result in a char, like in the example. If you print the result directly, cout << toupper('a') prints 65 (the ASCII value of A), not A.
The toupper function is defined in the <cctype> header file.
Tip: To change a whole string to uppercase, use a loop and call toupper() on each character.
Syntax
int toupper(int c);
Parameter Values
| Parameter | Description |
|---|---|
| c | Required. The character to convert. |
Technical Details
| Returns: | An int with the uppercase version of the character. If the character is not a lowercase letter, it is returned unchanged. |
|---|
Related Pages
Read more about strings in our Strings Tutorial.