Introduction
Vectors are built in arrays and supported by c++ compilers to reduce the effort to manage arrays and linked lists.
Description
The syntax of a single dimensional vector array is as follows .
std::vector<Type> Identifier
eg: std::vector<int> array;
Two create two dimensional arrays
std::vector<std::vector<type>> Identifier;
Eg : std::vector<std::vector<int> > m_2DintArray;
Don’t forget to put a space in between >> means “> put a space here >” else it will not parse correctly by the linux g++ compiler and may you will get an error like bellow
Error1 : Identifier not declared
or
Error2 : No scope for the identifier
There is lot of built in operations available for vectors. Some of them are given bellow
To resize the array dynamically.
Eg m_2DintArray.resize(2);
To insert values to array
m_2DintArray[0].push_back(iValues);
Retrieve values from array
int values= m_2DintArray[0].pop_back();
Delete array values
m_2DintArray[0].erase(); - Delete a value