C++ String erase()

This function removes the characters as specified, reducing its length by one.

Syntax

Consider a string str. Syntax would be:

Parameter

  • pos :It defines the position of the character which is to be removed.
  • len :It defines the number of characters to be erased.
  • Itr : It is an iterator to the character to be removed.
  • Range(first,last): It defines the range within the string to be removed.

Return value

It returns *this.

Example 1

Let's see a simple example when pos and len are given:

Output:

This is java tutorial

Example 2

Let's see a simple example when iterator is passed in a parameter:

Output:

java programing

Example 3

Let's see a simple example when the range is mentioned in a parameter:

Output:

This is an example of C

Next TopicC++ Strings




Latest Courses