Remove a word with find() and erase : string erase « string « C++ Tutorial






#include <iostream>
#include <string>
#include <cctype>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
  string strA("This is a test.");

  // Create an iterator to a string.
  string::iterator itr;

  cout << "Remove ' larger'.\n";
  itr = find(strA.begin(), strA.end(), 'l');
  strA.erase(itr, itr+7);
  cout << strA << "\n\n";

  return 0;
}








15.12.string erase
15.12.1.string.erase(6,9)
15.12.2.Remove a word with find() and erase
15.12.3.Use erase to remove all characters from (and including) location 6 through the end of string1
15.12.4.Three forms of erase() function from a string