C++ tolower()

The tolower() function in C++ converts a given character to lowercase.

tolower() Prototype

int tolower(int ch);

The tolower() function converts ch to its lowercase version if it exists. If the lowercase version of a character does not exist, it remains unmodified. The uppercase letters from A to Z is converted to lowercase letters from a to z respectively.

The behaviour of tolower() is undefined if the value of ch is not representable as unsigned char or is not equal to EOF.

It is defined in <cctype> header file.

tolower() Parameters

ch: The character to convert

tolower() Return value

The tolower() function returns a lowercase version of ch if it exists. Otherwise it returns ch.

Example: How tolower() function works

#include <cctype>
#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

int main()
{
    char str[] = "John is from USA.";

    cout << "The lowercase version of \"" << str << "\" is " << endl;

    for (int i=0; i<strlen(str); i++)
        putchar(tolower(str[i]));
    
    return 0;
}

When you run the program, the output will be:

The lowercase version of "John is from USA." is 
john is from usa.