C++ towlower()

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

The towlower() function is defined in <cwctype> header file.

towlower() prototype

wint_t towlower( wint_t ch );

The towlower() function converts ch to its lowercase version if it exists. If the lowercase version of a wide character does not exist, it remains unmodified.

The uppercase letters from A to Z is converted to lowercase letters from a to z respectively.


towlower() Parameters

  • ch: The wide character to convert

towlower() Return value

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

Example: How towlower() function works?

#include <cwctype>
#include <cwchar>
#include <iostream>
#include <clocale>
using namespace std;

int main()
{
	setlocale(LC_ALL, "en_US.UTF-8");

	wchar_t str[] = L"Ĵōhn Deńvėr";
	wcout << L"The lowercase version of \"" << str << L"\" is ";

	for (int i=0; i<wcslen(str); i++)
		putwchar(towlower(str[i]));

	return 0;
}

When you run the program, the output will be:

The lowercase version of "Ĵōhn Deńvėr" is ĵōhn deńvėr