Search⌘ K
AI Features

Solution: Erase the Capital Letters

Explore how to apply the std::erase_if algorithm with a lambda predicate to remove all capital letters from a string using C++20 container improvements. Understand the use of predicates for conditional erasure in containers.

We'll cover the following...

Solution

C++
#include <iostream>
#include <string>
int main() {
std::string str{"Only For TesTing PurPose."};
std::cout << "str: " << str << std::endl;
std::erase_if( str, [](char c){ return std::isupper(c); });
std::cout << "str: " << str << std::endl;
}

Applying the algorithm ...