// Using push_back method #include#include int main() { std::vector arr {1, 2, 3}; arr.push_back(4); arr.push_back(5); for (auto i : arr) { std::cout << i << " "; } return 0; }
// Using operator overloading #includeThis code uses operator overloading to append two new integers (4 and 5) to an existing array. The output will display: 1 2 3 ; 4 5 ; 1 2 3 4 5. Package Library: None - this example uses basic C++ functionality.int main() { int arr[3] {1, 2, 3}; int newArr[5] {4, 5}; for (int i : arr) { std::cout << i << " "; } std::cout << std::endl; for (int i : newArr) { std::cout << i << " "; } std::cout << std::endl; int size = sizeof(arr) / sizeof(arr[0]); for (int i = 0; i < sizeof(newArr) / sizeof(newArr[0]); i++) { arr[size + i] = newArr[i]; } for (int i : arr) { std::cout << i << " "; } return 0; }