i am using vectors stl but the following problem occurs in c++

  c++, stl, vector

my code

#include <bits/stdc++.h>
using namespace std;

int main() {
    
    int t;
    cin>>t;
    for(int i=0;i<t;i++)
    {vector<int> a;
        int n,x,sum=0,count=0;
     
       cin>>n>>x;
      for(int j=0;j<n;j++)
      {int y;
      cin>>y;
          a[j].push_back(y);
      }

and the problem is
" request for member ‘push_back’ in ‘a.std::vector<_Tp, _Alloc>::operator[]<int, std::allocator >(((std::vector::size_type)j))’, which is of non-class type ‘__gnu_cxx::__alloc_traitsstd::allocator<int >::value_type {aka int}’
a[j].push_back(y); "

Source: Windows Questions C++

LEAVE A COMMENT