std::string myStr = "Hello, world!"; myStr.erase(7, 5); // Deletes "world" // myStr now contains "Hello, !"
std::string myStr = "abcdefg"; myStr.erase(myStr.size()-1); // Deletes the last character "g" // myStr now contains "abcdef"
std::string myStr = "This will be cleared"; myStr.erase(); // Clears the entire string // myStr is now an empty stringThese examples demonstrate the various ways `erase()` can be used to manipulate strings. The function belongs to the C++ Standard Library.