std::vector<T,Allocator>::push_back

Appends the given element value to the end of the container.

# Declarations

void push_back( const T& value );

(constexpr since C++20)

void push_back( T&& value );

(since C++11) (constexpr since C++20)

# Parameters

# Return value

(none)

# Notes

Some implementations throw std::length_error when push_back causes a reallocation that exceeds max_size (due to an implicit call to an equivalent of reserve(size() + 1)).

# Example

#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
 
int main()
{
    std::vector<std::string> letters;
 
    letters.push_back("abc");
    std::string s{"def"};
    letters.push_back(std::move(s));
 
    std::cout << "std::vector letters holds: ";
    for (auto&& e : letters)
        std::cout << std::quoted(e) << ' ';
 
    std::cout << "\nMoved-from string s holds: " << std::quoted(s) << '\n';
}

# See also