0

In python, there's a function call append to add an item into the back of the list. Is there similar function in C++ to add an item into the array? Or is there any other alternative method so that I can add item into an array with undefined size?

#include <iostream>
using namespace std;

int main(){
    int list1[] = {1,2,3,4};
    //a function that add an item at the back of the array;
    cout<<list1[4]<<endl;
    return 0;
}
Xun
  • 1
  • 4
  • 2
    An array is fixed size, and cannot be appended to. A `std::vector` is dynamic, and can be appended to. – Eljay Sep 08 '21 at 01:34
  • `std::vector` has methods called `push_back()` and `emplace_back()`. `std::deque` also supports `push_front()` and `emplace_front()` on top of that. – Andrej Podzimek Sep 08 '21 at 01:37

0 Answers0