how we can write code to remove a character in c++

#include <iostream>
#include <string>

int main() {
    std::string str = "example";
    char charToRemove = 'p';

    size_t pos = str.find(charToRemove);
    if (pos != std::string::npos) {
        str.erase(pos, 1);
    }

    std::cout << "Modified string: " << str << std::endl;

    return 0;
}