How to use two dimensional array using vectors in c++ [ Linux and windows ]
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 

See All Responses Below...
Author
Message Rating
Posted on:
Please Login to Post Your Comments
Name (Max. 100 characters)
Please post your comments here
Select Language
Comments
Attach File(Max. Size: 2 MB)
A few simple rules when posting your Comments,
  1. Please post only answers relevant to the topic of discussion.
  2. Please dont misuse this site or do not be abusive, offensive, inappropriate,harass anyone on the boards or post ads or spam. Doing so will delete your inappropriate messages and will block or delete your account on this site. 

 
TekTipsDownload
GateExam
Academic Projects
TekTipsExperts
Android