-3

I made a vector of pairs and want to initialize values to those pairs using make pair but I get this error:

'struct std::pair<int, int>' has no member named 'push_back'

Here is my code:

const int maxm=100005;//10^5
vector<pair<int,int> > v(maxm);

int main(){
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        int x, y;
        scanf("%d %d",&x,&y);
        v[i].push_back(make_pair(x,y));
    }
}
Community
  • 1
  • 1
kolaveri
  • 59
  • 1
  • 2
  • 15

2 Answers2

3

That is because v[i] is of type std::pair<int, int>, you should:

v.push_back(make_pair(x,y));
marcinj
  • 48,511
  • 9
  • 79
  • 100
  • but i need to consider an array of maxn vectors – kolaveri Mar 26 '16 at 19:37
  • i got to make an array of vectors of pairs – kolaveri Mar 26 '16 at 19:39
  • `v.push_back` adds another pair to your vector at the index `i` - to have `array of maxn vectors` is not clear to me – marcinj Mar 26 '16 at 19:39
  • i need something like this (a1 a2 ) (,a2,a3,)(a4,a5 )......say 10 times – kolaveri Mar 26 '16 at 19:40
  • array of vectors would look like: `typedef std::vector > vec_type; vec_type arr[maxn];`, or better: `typedef std::vector > vec_type; std::array arr;` – marcinj Mar 26 '16 at 19:41
  • 1
    @kolaveri - If you want a vector of vectors of pairs then you should declare `v` as such. Hard to answer a question when it's so obfuscated. – Edward Strange Mar 26 '16 at 19:42
  • 1
    @kolaveri: "*i need something like this (a1 a2 ) (,a2,a3,)(a4,a5 )......say 10 times*" That is a vector of pairs, which you declared and created. That is *not* an array of vectors, which is what you keep saying you want. So you seem to be confused about the terms "array" and "vector". – Nicol Bolas Mar 26 '16 at 20:03
2
vector<pair<int,int> > v(maxm);

This just makes a single vector of size maxn. What you want is an array of vectors, so you should be doing

vector<pair<int,int> > v[maxm];
Raziman T V
  • 480
  • 1
  • 4
  • 12