C. Cretan C. Cretan - 1 month ago 8
C++ Question

Can't access member second of std::pair

I figured out how to store data in my

vector<vector<pair<int, int> > > v[1001];
doing it like this:

f >> x >> y; v[i][j].push_back(make_pair(x, y));

but I don't know how to access that data since it gives me the error:

c++ - error: '__gnu_cxx::__alloc_traits > >::value_type' has no member named 'second''|

at this line:

c[j] = c[j + 1] * (v[foo][j].second - v[foo][j].first + 1);

being a simple array
int c[1001];

My question is: What I'am doing wrong?

Answer Source

v is an array of vector of vector of pair. You need three indices:


Three indices is (almost always) too many. You need to encapsulate in some sort of structure.