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






Use erase to remove all characters from (and including) location 6 through the end of string1

  
 

#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:

 */        
    
  








Related examples in the same category

1.string.erase(6,9)
2.Erase a range of characters using an overloaded version of erase()