public member function

<string>

std::string::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;
}



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

string::back
Access last character (public member function)
string::push_back
Append character to string (public member function)
string::erase
Erase characters from string (public member function)