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