# 2.2.3.18.9 vector::vector

## Description

Default constructor for vector class.

Constructor to create a vector having size nSize.

Constructor to create a vector copy of an Origin Dataset.

Constructor to create a vector from a source column.

Complex vector constructor.

## Syntax

vector( )

vector( UINT nSize )

vector( Dataset & ds, BOOL bRemoveMissingValues = FALSE )

vector( Column & cc, int nLowerIndex = -1, int nUpperIndex = -1, int nWriteback = WRITEBACK_NO )

vector( vector & vR, vector & vI )

## Parameters

nSize
[input] Size of declared vector

ds
[input] The source dataset, value will copy to vector.
bRemoveMissingValues
[input] If true, will copy to value of Dataset and remove missing value to vector.

cc
[input] source column (it must be initialized properly prior to calling the constructor).
nLowerIndex
[input]the start index inside the column from which the copying should start;
If -1, the constructor scans from the beginning of the dataset until it finds the first nonmissing value. The value is remembered and can be accessed using the method GetSourceRange().
nUpperIndex
[input] the end index inside the column where the copying should end;
If -1, the constructor scans from the end of the dataset until it finds the first nonmissing value. The value is remembered and can be accessed using the method GetSourceRange().
nWriteback
[input] the combination of values from enumeration:
enum {
WRITEBACK_NO = 0, // no writeback
WRITEBACK_NO_RESIZE = 0x1, // writes back the vector without resizing or moving the data inside the column (not that both the vector and the column may have been resized between the construction and the writeback time).
WRITEBACK_INSERT_ON_EXPAND = 0x2, // not used if WRITEBACK_NO_RESIZE bit is present. If the vector has increased in size after the construction, on writeback the column will be expanded to accomodate additional values, all of which are going to be inserted after m_nSrcUpperIndex and any data (if) already present in the column,will be pushed to the right.
WRITEBACK_DELETE_ON_SHRINK = 0x8, // not used if WRITEBACK_NO_RESIZE bit is present. If the vector has decreased in size after the construction, on writeback the column will be shrunk for the size change, and any data (if present) that were to the right of m_nSrcUpperIndex will be pushed to the left.
};

vR
[input] real part of complex vector
vI
[input] image part of complex vector

## Examples

EX1

void vector_vector_ex1()
{
vector vD = {1.0, 2.0, 3.0, 4.0};         // vector of doubles
double dTest ;
dTest = vD[2];
printf("the dTest value is %f", dTest);

}

EX2

void vector_vector_ex2()
{
vector<string> vS = {"Hello", "World"}; // vector of strings
for(int n = 0 ; n<vS.GetSize(); n++)
out_str(vS[n]);
}

EX3

void vector_vector_ex3()
{
vector vD(10);			//vD is double
vector<int> vN(10);		//vN is int

printf("The double value is\n");
for(int n =0 ; n < vD.GetSize(); n++)
{
vD[n] = n*12;
printf("%.1f\n", vD[n]);
}

printf("The int value is\n");
for(int m =0 ; m < vN.GetSize(); m++)
{
vN[m] = m*12;
printf("%d\n", vN[m]);
}
}

EX4

void vector_vector_ex4()
{
Worksheet wks=Project.ActiveLayer();
if (wks)
{
Dataset dsB(wks,1);
dsB.SetSize(5);              // Set sizeof data set to 5
dsB[0]=-1;
dsB[1]=5;
dsB[2]=NANUM;                // Missing value will be removed
dsB[3]=NANUM;                // Missing value will be removed
dsB[4]=23;
vector vB( dsB, TRUE );      // Copy Dataset dsD to vector vD removing missing values
printf("The size of vB is %d", vB.GetSize()); // Elements dsB[2] and dsB[3] are removed
}
}

EX5

// Have some data in the second column of the current worksheet before running this example.
int    vector_vector_ex5()
{
Worksheet wks=Project.ActiveLayer();
Column		col(wks, 1);
vector		v(col, 2, 5, WRITEBACK_DELETE_ON_SHRINK | WRITEBACK_INSERT_ON_EXPAND);

// Dump the source range
int		nSrcLowerIndex, nSrcUpperIndex;
if ( v.GetSourceRange ( nSrcLowerIndex, nSrcUpperIndex ))
printf("nSrcLowerIndex = %ld\tnSrcUpperIndex = %ld\n", nSrcLowerIndex, nSrcUpperIndex);

// Modify the vector:
int		nNewVectorSize = 80;
v.SetSize(nNewVectorSize);
for (int ii = 0; ii < nNewVectorSize; ii++)
{
v[ii] = 100 * (ii + 1);
printf ("%.1f\n", v[ii])
}

return 0;
}

EX6

void vector_vector_ex6()
{
vector vR = { 1, 2, 3 };
vector vI = { 4, 5, 6 };
vector<complex> vComplex(vR, vI);

for(int ii = 0; ii < vComplex.GetSize(); ++ii)
{
out_complex("", vComplex[ii]);
}
/*
Output:
1.000000+4.000000i
2.000000+5.000000i
3.000000+6.000000i
*/
}

## Remark

For the constructor to create a complex vector from two vectors - one containing the Real parts the other containing the Imaginary parts. The input vectors must have a base type of double and must have the same number of elements.