Search
 
SCRIPT & CODE EXAMPLE
 

CPP

remove element from array c++

int array[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};

// delete 3 (index 2)
for (int i = 2; i < 8; ++i)
    array[i] = array[i + 1]; // copy next element left
Comment

remove element from array c++

// remove *all* 3's, return new ending (remaining elements unspecified)
auto arrayEnd = std::remove(std::begin(array), std::end(array), 3);
Comment

C++ program to delete an element from an array

#include<iostream>
using namespace std;
int main()
{
    int arr[10], tot=10, i, elem, j, found=0;
    cout<<"Enter 10 Array Elements: ";
    for(i=0; i<tot; i++)
        cin>>arr[i];
    cout<<"
Enter Element to Delete: ";
    cin>>elem;
    for(i=0; i<tot; i++)
    {
        if(arr[i]==elem)
        {
            for(j=i; j<(tot-1); j++)
                arr[j] = arr[j+1];
            found++;
            i--;
            tot--;
        }
    }
    if(found==0)
        cout<<"
Element doesn't found in the Array!";
    else
        cout<<"
Element Deleted Successfully!";
    cout<<endl;
    return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: how to erase a certain value from a vector in C++ 
Cpp :: strlen in c++ 
Cpp :: concatenate string program in c++ 
Cpp :: c++ vector extend vector 
Cpp :: cpp cin 
Cpp :: on component begin overlap c++ 
Cpp :: C++ break and continue 
Cpp :: divide and conquer based algorithm to find maximum and minimum of an array 
Cpp :: c++ how to read from a file 
Cpp :: string.begin() c++ 
Cpp :: joins in mysql use sequelize 
Cpp :: clear qlayout 
Cpp :: c++ set comparator 
Cpp :: why is using namespace std a bad practice 
Cpp :: Accpt array input in single line in cpp 
Cpp :: what is thread in c++ 
Cpp :: how to sort vector of struct in c++ 
Cpp :: how to empty an array c++ 
Cpp :: c++ insert into map 
Cpp :: Palindrome String solution in c++ 
Cpp :: new float array c++ 
Cpp :: c++ uint32_t 
Cpp :: tree to array c++ 
Cpp :: unordered_map contains key 
Cpp :: quick sort 
Cpp :: c++ split string by space into array 
Cpp :: maxheap cpp stl 
Cpp :: how to format decimal palces in c++ 
Cpp :: sum array c++ 
Cpp :: pass map as reference c++ 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =