vector::RemoveAt

Description

Removes one or more elements starting at a specified index in an vector. It can removes elements at specified indices in a vector also.

Syntax

BOOL RemoveAt( int nIndex, int nCount = 1 )

BOOL RemoveAt(const vector<int>& vnIndices)

Parameters

nIndex
[input] A specified index in vector.
nCount
[input] The number of elements to remove (defaults to 1).

vnIndices
[input] vector of indices of elements to remove

Return

Always returns TRUE

Examples

EX1

void vector_RemoveAt_ex1()
{
    vector<string> vsExt = {"OPJ", "TXT", "SPC"};
    vsExt.RemoveAt(0, 2);

    for(int ii = 0; ii < vsExt.GetSize(); ii++)
    {
        printf("Extesion(%d) : %s\n", ii, vsExt[ii]);
    }
}
//Result: 
//                Extesion(0) : SPC

EX2

void vector_RemoveAt_ex2()
{
    vector vdElements = {123, 10, 23};
    vector<int> vnIndices = {0, 2};
    vdElements.RemoveAt(vnIndices);
    
        for(int ii = 0; ii < vdElements.GetSize(); ii++)
        {
                printf("%.f\n", vdElements[ii]);
        }
        //Output will be: 10
}

Remark

Removes one or more elements starting at a specified index in a vector. In the process, it shifts down all the elements above the removed element(s). It decrements the upper bound of the vector. If nIndex is out of bound, or if (nIndex + nCount-1)is out of bound, then runtime error will be generated.


Removes elements at specified indices in a vector. In the process, it shifts down all the elements above the removed element(s) which are not removed. It decrements the upper bound of the vector. If the size of the indices is zero or any of the indices is out of bound, then runtime error will be generated. The duplicated indices will be skipped.

See Also

vector::InsertAt, vector::InsertValue

header to Include

origin.h