Use erase to remove all characters from (and including) location 6 through the end of string1 : string erase « string « C++ Tutorial






#include <iostream>
using std::cout;
using std::endl;

#include <string>
using std::string;

int main()
{
   string string1( "abcedfghijklmnopqrstuvwxyz" );
   
   cout << "Original string:\n" << string1 << endl << endl;

   string1.erase( 6 );

   cout << "Original string after erase:\n" << string1
      << "\n\nAfter first replacement:\n";
             
   return 0;
}
Original string:
abcedfghijklmnopqrstuvwxyz

Original string after erase:
abcedf

After first replacement:








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