Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
std::basic_...ng::pop_back(3) C++ Standard Libarystd::basic_...ng::pop_back(3)

NAME
       std::basic_string::pop_back - std::basic_string::pop_back

Synopsis
	  void pop_back();  (constexpr since C++20)

	  Removes the last character from the string.

	  Equivalent  to  erase(end()  -  1). The behavior is undefined	if the
       string is empty.

Parameters
	  (none)

Return value
	  (none)

Complexity
	  Constant.

Exceptions
	  Throws nothing.

Notes
	  In libstdc++,	pop_back() is not available in C++98 mode.

Example
       // Run this code

	#include <cassert>
	#include <iomanip>
	#include <iostream>
	#include <string>

	int main()
	{
	    std::string	str("Short string!");
	    std::cout << "before=" << std::quoted(str) << '\n';
	    assert(str.size() == 13);

	    str.pop_back();
	    std::cout << " after=" << std::quoted(str) << '\n';
	    assert(str.size() == 12);

	    str.clear();
	//  str.pop_back(); // undefined behavior
	}

Output:
	before="Short string!"
	 after="Short string"

	  Defect reports

	  The following	behavior-changing defect reports were applied retroac-
       tively to
	  previously published C++ standards.

	    DR	     Applied	to		   Behavior    as    published
       Correct behavior
	  LWG  534  C++98	std::basic_string  did	not  have  the	member
       added
			     function pop_back()

See also
	  push_back appends a character	to the end
		    (public member function)
	  erase	    removes characters
		    (public member function)

http://cppreference.com		  2024.06.10	 std::basic_...ng::pop_back(3)

Want to link to this manual page? Use this URL:
<https://man.freebsd.org/cgi/man.cgi?query=std::basic_string::pop_back&sektion=3&manpath=FreeBSD+Ports+15.1.quarterly>

home | help