tolower() Function in C++
The C++ tolower() function converts an uppercase alphabet to a lowercase alphabet. It is a predefined function of ctype.h header file. If the character passed is an uppercase alphabet, then the tolower() function converts an uppercase alphabet to a lowercase alphabet. This function does not affect another lowercase character, special symbol, or digit.
int tolower(int ch);
Parameter:
- ch: It is the character to be converted to lowercase.
Return Value: This function returns the ASCII value of the lowercase character corresponding to the ch.
In C++, typecasting of int to char is done as follows:
char c = (char) tolower('A');
Below programs illustrate the tolower() function in C++:
Example 1:
C++
#include <iostream>
using namespace std;
int main()
{
char c = 'G' ;
cout << c << " in lowercase is represented as = " ;
cout << ( char ) tolower (c);
}
|
Output
G in lowercase is represented as = g
Example 2:
C++
#include <bits/stdc++.h>
using namespace std;
int main()
{
string s = "GEEKSFORGEEKS" ;
for ( auto & x : s) {
x = tolower (x);
}
cout << s;
return 0;
}
|
Note: If the character passed in the tolower() is any of these three
- lowercase character
- special symbol
- digit
tolower() will return the character as it is.
Example 3:
C++
#include <iostream>
using namespace std;
int main() {
string s= "Geeks@123" ;
for ( auto x:s){
cout << ( char ) tolower (x);
}
return 0;
}
|
Last Updated :
11 Mar, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...