Case conversion refers to converting a letter from one case to another, such as converting a lowercase letter to uppercase or vice versa. The C++ standard library provides several functions for performing case conversion, including:
toupper(char)
: This function converts a single character to its uppercase equivalent. If the input character is already uppercase, it is returned unmodified. The function takes a char argument and converts that character to uppercase.
tolower(char)
: This function converts a single character to its lowercase equivalent. If the input character is already lowercase, it is returned unmodified. The function takes a char argument and converts that character to lowercase.
toupper
The following code shows how we can convert a character from lowercase to uppercase:
#include <iostream>using namespace std;int main(){char input = 'a';char converted_input = toupper(input);cout << "The uppercase of " << input << " is " << converted_input << endl;return 0;}
input
of type char
, and assign a
to it.toupper()
to convert input
character to uppercase.tolower
The following code shows how we can convert a character from uppercase to lowercase:
#include <iostream>using namespace std;int main(){char input = 'A';char converted_input = tolower(input);cout << "The lowercase of " << input << " is " << converted_input << endl;return 0;}
input
of type char
, and assigning A
to it.tolower()
to convert input
character to lowercase.Free Resources