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

FreeBSD Manual Pages

  
 
  

home | help
std::basic_...::push_back(3)  C++ Standard Libary std::basic_...::push_back(3)

NAME
       std::basic_string::push_back - std::basic_string::push_back

Synopsis
	  void push_back( CharT	ch );  (constexpr since	C++20)

	  Appends the given character ch to the	end of the string.

Parameters
	  ch - the character to	append

Return value
	  (none)

Complexity
	  Amortized constant.

Exceptions
	  If  the  operation  would  result  in	 size()	 >  max_size(),	throws
       std::length_error.

	  If an	exception is thrown for	any reason, this function has  no  ef-
       fect (strong
	  exception safety guarantee).

Example
       // Run this code

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

	int main()
	{
	    std::string	str{"Short string"};
	    std::cout << "1) " << std::quoted(str) << ", size: " << str.size()
       << '\n';

	    str.push_back('!');
	    std::cout << "2) " << std::quoted(str) << ", size: " << str.size()
       << '\n';
	}

Output:
	1) "Short string", size: 12
	2) "Short string!", size: 13

	  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
			     (1) the description was missing in
	  LWG  7   C++98      the C++ standard			  (1) descrip-
       tion added
			     (2) the parameter type was	const	  (2)  changed
       to CharT
			     CharT
	  LWG  847 C++98      there was	no exception safety	  added	strong
       exception safety
			     guarantee				 guarantee

See also
	  pop_back removes the last character
	  (DR*)	   (public member function)

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

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

home | help