Strings In Depth14 / 15
Up next

Uppercase with ranges

#include <print>
#include <string>
#include <ranges>
#include <algorithm>
#include <cctype>

int main() {
    std::string s = "hello";
    // build an uppercased copy character by character
    auto upper = s | std::views::transform([](unsigned char c) {
        return static_cast<char>(std::toupper(c));
    });
    std::string result{upper.begin(), upper.end()};
    std::println("{}", result);
}
What you're solving

transform each character