mardi 11 août 2020

Store pair values in vector C++ from a 2d vector

I've been given a 2D vector (A). I need to store values of row and column index of that vector which contains element 0.

Here is my code-

vector<pair<int,int>>v;
   for(int i=0;i<A.size();i++){
       for(int j=0;j<A[i].size();j++){
           if(A[i][j]==0){
               v.push_back(make_pair(i.first,j.second));
           }
       }
   }

But I've been getting this error

error: '__gnu_cxx::__alloc_traitsstd::allocator<std::vector<int >, std::vector >::value_type' {aka 'class std::vector'} has no member named 'first'

error: '__gnu_cxx::__alloc_traitsstd::allocator<std::vector<int >, std::vector >::value_type' {aka 'class std::vector'} has no member named 'second'

Aucun commentaire:

Enregistrer un commentaire