> For the complete documentation index, see [llms.txt](https://lintcode-solutions.gitbook.io/project/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lintcode-solutions.gitbook.io/project/oj-review/aug-29-2018.md).

# Aug 29, 2018

## C++

### `std::vector::push_back()`

```cpp
void push_back (const value_type& val);
void push_back (value_type&& val);
```

Adds a new element at the end of the [vector](http://www.cplusplus.com/vector), after its current last element. The content of val is copied (or moved) to the new element.\
\
This **effectively increases the container** [**size**](http://www.cplusplus.com/vector::size) **by one**, which causes an automatic reallocation of the allocated storage space if -and only if- the new vector [size](http://www.cplusplus.com/vector::size) surpasses the current vector [capacity](http://www.cplusplus.com/vector::capacity).

```cpp
// vector::push_back
#include <iostream>
#include <vector>

int main ()
{
  std::vector<int> myvector;
  int myint;

  std::cout << "Please enter some integers (enter 0 to end):\n";

  do {
    std::cin >> myint;
    myvector.push_back(myint);
  } while (myint);

  std::cout << "myvector stores " << int(myvector.size()) << " numbers.\n";

  return 0;
}
```
