std::basic_string<CharT,Traits,Allocator>::push_back

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

# Declarations

void push_back( CharT ch );

(constexpr since C++20)

# Parameters

# Return value

(none)

# Example

#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';
}

# Defect reports

DRApplied toBehavior as publishedCorrect behavior
LWG 7C++981) the description was missing in the C++ standard2) the parameter type was const CharT1) description added2) changed to CharT
LWG 847C++98there was no exception safety guaranteeadded strong exception safety guarantee

# See also