My Professional Profile

I am Johnson Augustine Sr.Software Engineer and System Architect. I have 10 Yrs of hands on expertise in MVC 5 , Angular 5 , C# MVC Razor, WPF MVVM , Android , IOS Swift 3 , IOS11 MSSQL,MySQL Database,,PHP,C/C++/Visual C++/G++/QT++,Com,DirectX,Open CV,EMGU CV , embedded System Development , [Raspberry PI]. ,html,Javascript,Jquery,Ajax.CSS , Networking ,Cyber security, Ethical Hacking You can see my professional profile at Email :

Thursday, 16 May 2013

How to use two dimensional array using vectors in c++ [ Linux and windows ]


Vectors are built in arrays and supported by c++ compilers to reduce the effort to manage arrays and linked lists. 


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  
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

Retrieve values from array
int values= m_2DintArray[0].pop_back();

Delete array values
m_2DintArray[0].erase(); - Delete a value 

For more discussions please visit : 

No comments:

Post a Comment

Note: only a member of this blog may post a comment.