Link to home
Start Free TrialLog in
Avatar of Beebutter
Beebutter

asked on

How to store values in two dimensional vector

I need to read data from a matrix and store it in two dimensional vector.
Say the matrix file is
4
0 1 1 0
1 0 0 0
1 3 1 1
1 0 0 1
The first number 4 indicates the size of the matrix, say 4X4 matrix.
I have to read this data from the file and store it in a two dimensional vector.
I initialized the vector as vector<vector<int> > myVector;
I tried storing like this
for (rows = 0; rows < size; rows++) {
for (columns = 0; columns < size; columns++) {
inputFile >> value;
myVector[rows][columns] = value; // not working
cout<<rows<<" "<<columns<<" "<<myVector[rows][columns]<<endl; // not working
}
}

Also I need help in how should I access the elements in the vector after inserting.
Please let me know how to do this.
ASKER CERTIFIED SOLUTION
Avatar of Zoppo
Zoppo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial