Facebook Page Twitter Page LinkedIn Page
× C++ Standard Library C++ STL Library


The C++ string::pop_back function is used to delete the last character of the string. Every deletion of character results into reducing the string size by one unless the string is empty.

Syntax

void pop_back();

Parameters

No parameter is required.

Return Value

None.

Time Complexity

Constant i.e, Θ(1).

Example:

In the below example, the string::pop_back function is used to delete last character of the string called MyString.

#include <iostream>
#include <string>
using namespace std;
 
int main (){
  string MyString = "ALPHA";

  //deletes last character of the string
  MyString.pop_back();
  //deletes next last character of the string
  MyString.pop_back();

  cout<<MyString;

  return 0;
}

The output of the above code will be:

ALP

❮ C++ - String Functions