In C++, there is no built-in method to convert an entire string to uppercase or lowercase. Instead, use std::transform with ::toupper or ::tolower from <algorithm>:
string s = "Hello World";
string upper = s;
transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
// upper == "HELLO WORLD"
string lower = s;
transform(lower.begin(), lower.end(), lower.begin(), ::tolower);
// lower == "hello world"
transform applies a function to each character. ::toupper converts a character to uppercase, and ::tolower converts it to lowercase.
Assignment
Follow the Coding Tutorial and create upper and lower versions of word!
Hint
Use transform with ::toupper for uppercase and ::tolower for lowercase.
Free plan: 30 tutor messages. PRO is unlimited.
Saved
Ctrl + Enter to check
