How to access an element of a vector that lies inside a pair?

Suppose I have this data type : vector< pair< int, vector > > v;
Now I want to access some element of the vector that is inside the pair (v[i].second is the vector and I have to access some element of v[i].second). How to do it without copying it into another vector.

v[i].second[j];
6 Likes

v[i].S[j] :wink:

if you want to access i^{th} element of the vector v then you do v[i] . This will give you the resultant element of pair type.
pair<int, vector> temp = v[i];
now you have to access the second element of the pair which is an vector then you will do this by
vector vect = temp.second;

Now you have to access the j^{th} element of vect then you will simply do this by
vect[j]

So effectively in single line do
v[i].second[j];

1 Like