From cppreference.com
voidpush_back(CharTch);(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 cause
to exceed
, throws
.
If an exception is thrown for any reason, this function has no effect (
strong exception safety guarantee
).
Example
Run this code
#include<iomanip>#include<iostream>#include<string>intmain(){std::stringstr{"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 retroactively to previously published C++ standards.
DR Applied to Behavior as published Correct behavior
C++98 1) the description was missing in the C++ standard
2) the parameter type was constCharT1) description added
2) changed to CharT
C++98 there was no exception safety guarantee added strong exception safety guarantee See also
(DR*)
removes the last character
(public member function)