output of 2-d vector using copy

compiler: g++ 4.8.4, os: ubuntu 14.04.1

I'm trying to output a 2-d vector using copy. The code below does
print the 2-d vector, however it does not print the row numbers.
I was considering somehow deriving the row number from the address
of the begin iterator, except I'm unclear about how to set this up.
Could someone pls clarify how to modify this code (if possible).

Thanks,

-------------------------------------------------------------------
[code]
#include <iostream>
#include <algorithm>
#include <vector>
#include <iterator>

typedef std::vector<int> VI;
typedef std::vector<VI> VVI;
VVI::iterator it;

namespace std {
ostream& operator<<(ostream& o, VI& v) {
std::cout << &(*it) << ": ";
std::cout << &(*v.begin()) << ": ";
copy (v.begin(), v.end(), ostream_iterator<int>(std::cout, ", "));
return o;
}
}

int main () {
VI v1 {30, 31, 32};
VI v2 {40, 41, 42};
VVI vv;
vv.push_back(v1);
vv.push_back(v2);
it = vv.begin();
copy (vv.begin (), vv.end (), std::ostream_iterator<VI&>(std::cout, "\n"));
return 0;
}
[\code]

--------------------------------------------------------------------

Output:
[code]
0x198a090: 0x198a070: 30, 31, 32,
0x198a090: 0x198a0d0: 40, 41, 42,
[\code]
Topic archived. No new replies allowed.