The tolower() function in C++ is used to convert an uppercase alphabet character into its lowercase equivalent. It is a predefined function available in the <cctype> header file.
- It converts uppercase characters (A-Z) into lowercase characters (a-z).
- Lowercase letters, digits, and special symbols remain unchanged.
Example: Convert Single Character to Lowercase
#include <iostream>
using namespace std;
int main()
{
char c = 'G';
cout << c << " in lowercase is represented as = ";
// tolower() returns an int value there for typecasting
// with char is required
cout << (char)tolower(c);
}
Output
G in lowercase is represented as = g
Syntax
int tolower(int ch);
Parameter:
- ch: Character to be converted into lowercase
Return Value:
- The function returns the ASCII value of the lowercase character corresponding to the given character.
Header File:
#include <cctype>
Example: Convert String to Lowercase
#include <bits/stdc++.h>
using namespace std;
int main()
{
// string to be converted to lowercase
string s = "GEEKSFORGEEKS";
for (auto& x : s) {
x = tolower(x);
}
cout << s;
return 0;
}
Output
geeksforgeeks
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: Lowercase Conversion with Digits and Symbols
#include <iostream>
using namespace std;
int main() {
string s="Geeks@123";
for(auto x:s){
cout << (char)tolower(x);
}
return 0;
}
Output
geeks@123