#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
template<typename T, size_t Size>
std::istream& operator>>(std::istream& in, T (&arr)[Size])
{
std::for_each(std::begin(arr), std::end(arr), [&in](auto& elem) {
in >> elem;
});
return in;
}
void solve()
{
int n, q;
cin>>n>>q;
int pre[n], a[n];
memset(pre, 0, sizeof(pre));
cin >> a; // this statement is not working giving compilation error as:-
"no operator ">>" matches these operands C/C++(349)
a.cpp(167, 7): operand types are: std::istream >> long long [n]"
}
#undef int
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t = 1;
cin >> t;
while (t--)
solve();
return (int)0;
}
The above written cin code in the solve function for taking an array input using operator overloading is not working, why so? I am trying to use the operator overloading for input stream operator cin and trying to use it to input an array and then process it over. So overall reducing time by cin cin ... a lot. I have taken reference from Link .