i am using std::vector but the following problem occurs in c++ [closed]

  c++, std, 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<int> >(((std::vector<int>::size_type)j))’, which is of non-class type ‘__gnu_cxx::__alloc_traits<std::allocator<int> >::value_type {aka int}’
        a[j].push_back(y);

Source: Windows Questions C++

LEAVE A COMMENT