- 1 year ago
How to use tolower or toupper with a special character such as Å
Comment
1 / 1
You can use std::tolower
or std::toupper
functions from the <locale>
header file to convert a character to its lowercase or uppercase form, respectively. These functions can handle special characters such as Å if the appropriate locale is set.
Here's an example that converts the character 'Å' to lowercase:
cpp#include <iostream>
#include <locale>
int main() {
char c = 'Å';
std::locale loc("en_US.UTF-8");
std::cout << std::tolower(c, loc) << '\n';
return 0;
}
Output:
å
Note that you need to provide a valid locale object as the second argument to std::tolower
or std::toupper
. In this example, the "en_US.UTF-8"
locale is used. You can replace it with the appropriate locale for your system.