public member function
<string>

std::string::pop_back

void pop_back();
Delete last character
Erases the last character of the string, effectively reducing its length by one.

Parameters

none

Return value

none

Example

1
2
3
4
5
6
7
8
9
10
11
// string::pop_back
#include <iostream>
#include <string>

int main ()
{
  std::string str ("hello world!");
  str.pop_back();
  std::cout << str << '\n';
  return 0;
}

hello world


Complexity

Unspecified, but generally constant.

Iterator validity

Any iterators, pointers and references related to this object may be invalidated.

Data races

The object is modified.

Exception safety

If the string is empty, it causes undefined behavior.
Otherwise, the function never throws exceptions (no-throw guarantee).

See also