::TOLOWER
This converts a single character to its lowercase equivalent. The function takes a single argument, typically of type int
representing an ASCII character, and returns the corresponding lowercase character if the input is an uppercase letter; otherwise, it returns the character unchanged. ::tolower
is often used when performing case-insensitive comparisons, normalizing user input, or processing text to ensure uniformity. For example, converting all characters of a string to lowercase before comparison allows developers to ignore differences in capitalization. It is important to note that ::tolower
operates on one character at a time, so when working with strings, it is commonly used in loops or with standard algorithms like std::transform
.
#include <algorithm> // For transform
transform(
str.begin(), // Start of the string
str.end(), // End of the string
str.begin(), // Destination (same string)
::tolower // Function applied to each character (convert to lowercase)
);
#include <iostream> // For input and output
#include <string>
#include <cctype>
#include <algorithm> // For transform
using namespace std;
int main() {
string str = "C++ Programming Is Powerful!"; // Original string
transform(str.begin(), str.end(), str.begin(), ::tolower); // Convert to lowercase
cout << "Lowercase String: " << str << endl; // Display result
return 0; // End of program
}
Last updated