how to remove element at a given index C++ code example

Example 1: how to erase elemts accoding to index c++

arr.erase(arr.begin() + i);

Example 2: delete index from array c++

const int SIZE = 9;
	int arr[SIZE];
	cout << "Enter numbers: \n";
	for (int i = 0; i < SIZE; i++)
		cin >> arr[i];
	for (int i = 0; i < SIZE; i++)
		cout << arr[i] << "\t";
	cout << endl;
	
	cout << "Enter Index U want to delete:\n";
	int del;
	cin >> del;
	for (int i = del-1; i < SIZE; i++)
	{
		arr[del] = arr[del + 1];
		del++;
	}
	for (int i = 0; i < SIZE - 1; i++)
		cout << arr[i] << "\t";
	cout << endl;

Tags:

Cpp Example