Mega Code Archive

 
Categories / C++ Tutorial / String
 

Three forms of erase() function from a string

#include <iostream> #include <string> using namespace std; int main() {     string word1 = "Game";     string word2("Over");     string word3(3, '!');     string phrase = word1 + " " + word2 + word3;     cout << phrase << endl;     phrase.erase(4, 5);     cout << "The phrase is now: " << phrase << endl;     phrase.erase(4);     cout << "The phrase is now: " << phrase << endl;     phrase.erase();     cout << "The phrase is now: " << phrase << endl;     return 0; }