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;
}
2
  • 2
    An array is fixed size, and cannot be appended to. A std::vector is dynamic, and can be appended to. Commented Sep 8, 2021 at 1:34
  • std::vector has methods called push_back() and emplace_back(). std::deque also supports push_front() and emplace_front() on top of that. Commented Sep 8, 2021 at 1:37

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.