I want to insert values of two arrays : A
and T
in an std::unordered_map
(named unordered
) by following code:
for(int i = 0; i < N; ++i)
{
unordered.insert(std::make_pair<int, int>(A[i], T[i]));
}
I am getting the following error:
error: cannot bind rvalue reference of type ‘int&&’ to lvalue of type ‘int’
I guess it is because the operator[]
returns a reference to a variable, but then how to do it otherwise?
This is the rest of my code:
int N;
cin >> N;
int A[N], T[N];
std::unordered_map<int, int> unordered;
for (int i = 0; i < N; ++i)
{
cin >> A[i];
}
for (int i = 0; i < N; ++i)
{
cin >> T[i];
}
for (int i = 0; i < N; ++i)
{
unordered.insert(std::make_pair<int, int>(A[i], T[i]));
}