To iterate through and print the elements of a single dimensional vector I use,
vector<int> a;
for(vector<int>::iterator it=a.begin();it<a.end();it++)
cout<<*it;
How do I do the same for a two dimensional Vector?
Or since we're using c++11...
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<vector<int> > v = {{1,2}, {3,4}};
for (const auto& inner : v) {
for (const auto& item : inner) {
cout << item << " ";
}
}
cout << endl;
return 0;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With