c++ stl pair error

code link : http://ideone.com/pYCzT0

Here i want to print element of vector without iterator but in doing so i m getting an error

error: ‘class std::vector<std::pair<char, int> >’ has no member named ‘first’

error: ‘class std::vector<std::pair<char, int> >’ has no member named ‘second’

what is wrong in my code??

Because your ch3 is an array of vector, so you should do “cout<<ch3*[j].first<<” “<<ch3*[j].second<<”
" " or something like that.

why do we use a 2d array notation when i m using a 1d array???

BY the way it is working by your method!!!

We need to use 2d array notation because, you declared 1D vector and vector is itself a dynamic array, so by using this vector < pair < char, int > > ch3[c+1] declaration you’re actually declaring dynamic 2d array

1 Like