2.2.3.18.8 vector::SetAtGrow

Description

Sets the vector element at the specified index.

Syntax

BOOL SetAtGrow( int nIndex, _TemplType element )

Parameters

nIndex
[input] A specified index in vector.
element
[input] The element to be added to this vector.

Return

Always returns TRUE

Examples

EX1

//Set the new string into string vector at the specified index. 
void vector_SetAtGrow_ex1()
{
    vector<string> vsExt = {"OPJ", "TXT"};
    vsExt.SetAtGrow(0, "SPC");		//The new string will replace the existing one
    
    for(int i = 0; i < vsExt.GetSize(); i++)
        printf("%s ", vsExt[i]);
		// Now vsExt is : {"SPC","TXT"}
	
	printf("\n");
    vsExt.SetAtGrow(5, "ORG");		//The new string will extend the existing one  
    for(int ii = 0; ii < vsExt.GetSize(); ii++)
        printf("Extesion(%d): %s\n", ii, vsExt[ii]);
		//now vsExt is : {"SPC", "TXT", "", "", "", "ORG"}
}

EX2

//Set double data to double vector at the specified index.
void vector_SetAtGrow_ex2()
{
	vector<double> vD = {1.1, 2.2};
	double d1 = (3.999); 
	double d2 = (4.8);
    vD.SetAtGrow(1, d1);	//New data will replace the existing one
	vD.SetAtGrow(3, d2);	//New data will extend the existing one
	
    for(int ii = 0; ii < vD.GetSize(); ii++)	
	out_double("",vD[ii]);
    //Output: 1.1, 3.999, 0, 4.8
}

EX3

//Set complex data to complex vector at the specified index.
void vector_SetAtGrow_ex3()
{	
    vector<complex> vC;
    complex cc1(4.3, 5.6);
	complex cc2(3, 2);
	complex cc3(2, 1);
	
    vC.Add(cc1);
    vC.Add(cc2);
    vC.SetAtGrow(2, cc3);	//New complex data will extend the existing one
	
    for(int ii = 0; ii < vC.GetSize(); ii++)	
	out_complex("",vC[ii]);
    //Output: 
			//4.300000+5.600000i
			//3.000000+2.000000i
			//2.000000+1.000000i
}

Remark

See Also

vector::InsertAt

Header to Include

origin.h