Array::InsertAt

 

Description

Inserts one element at a specified index in the array.

Syntax

BOOL InsertAt( int nIndex, _TemplType newElement )

Parameters

nIndex
[input] A specified index in the array.
newElement
[input] The element to be added to this array.

Return

Returns a boolean indicating success or failure of the requested operation

Examples

#include <Array.h>
struct PERSON
{
        int nID;
};
void Array_InsertAt_ex1()
{
        Array<PERSON&> arp(true); //is owner
        for ( int ii = 0; ii < 4; ii++ )
        {
                PERSON* tp = new PERSON;
                tp->nID = ii + 1;
                arp.Add(*tp);
        }
        for ( ii = 0; ii < arp.GetSize(); ii++ )
                printf("Person %d's ID is : %d\n", ii + 1, arp.GetAt(ii).nID);
        
        PERSON* pp = new PERSON;
        pp->nID = 12345;
        if ( !arp.InsertAt(0, *pp) )
                out_str("Fail to insert at the first item.");
        
        for ( ii = 0; ii < arp.GetSize(); ii++ )
                printf("Person %d's ID is : %d\n", ii + 1, arp.GetAt(ii).nID);
}

Remark

See Also

Array::Add
Array::RemoveAt

header to Included

Array.h