How to use two dimensional array using vectors in c++ [ Linux and windows ]
Rate this article
0 out of 5
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 


About The Author
Johnson Augustine
I am Johnson Augustine [My friends calls me - J.A), Completed my Master of Computer Applications degree, and Currently working as a Software Engineer at KTS Infotech PVT LTD and Server Admin and security Engineer at Scibero Hosting and Cyber Solutions. I have expertise in  C/C++/Visual C++/G++/QT++,Com,Device Driver and embedded System Development. I have 4 Year Experience in ASP.net and Visual studio 2005,2008,2010 and MSSQL Server 2000,2005,2008 ,I have also deep knowledge in Oracle database,MySQL Database,C++ with SQLite, Android mobile development , PHP , Joomla,Word Press ,html,Javascript,Jquery,Ajax.CSS , Networking ,Cyber security, Ethical Hacking and familiar with most of the web hosting control panels like Plesk 9.5,Plesk 10.4.4,Plesk 11.0.9 . Cpanel/WHM,Hsphere,Dotnet panel , and have experience in Windows server 2003,2008,Cent Os , RHEL,Fedora etc .and also have some work experience in cloud environment. 

You can see my professional profile at http://linkedin.com/in/johnsontaugustine

Tektip profile [Popular Technical Discussion Website ] : http://www.tektips.in/AuthorDetails.aspx?AID=technogreenworld@gmail.com

See my personal technical discussion website http://www.memcpy.in
Number Of articles Posted
8
Number Of Messages Posted
23
Joined Date
0
   
Author
Messages
Posted:
Post Your Comments
Name (Max 50 Chars)
Comments

 
TekTipsDownload
GateExam
Academic Projects
TekTipsExperts
Android