I'm having trouble outputting a multi-dimensional vector that has specific values.
Code:
void DisplayVect (const vector<vector<int> >& v);
int main(){
const int Max = 7;
vector<vector<int> > v(8,5);
DisplayVect(v);
system("Pause");
}
void DisplayVect (const vector<vector<int> >& v)
{ for (int i = 0; i < v.size(); i++) // loops through each row of v
{ for (int j = 0; j < v[i].size(); j++) // loops through each element of each row
cout << v[i][j] << " "; // prints the jth element of the ith row
cout << endl;
}
}
That code above works fine, but as far as assigning values, this code will add on to the vector of 0's with values from 0 to 6, instead of changing the values that are already printed.
Code:
for(int i = 0; i < Max; i++){
for(int j = 0; j < Max; j++){
v[i].push_back(j);
}
}
Thanks for your help.