I am getting an error in this code? Can someone tell the reason? A similar code available on GFG works although.
Attached is the code.
assume the header file bits/stdc++.h
and namespace std
.
int main()
{
int n;
cin >> n;
map<ll, vector<int>> val;
ll arr[n] = { 0 };
for (int i = 0; i < n; i++) cin >> arr[i];
for (int i = 0; i < n; i++) val[arr[i]].push_back(i);
for (auto i : val)
{
cout << "Element Indexes\n";
cout << val.first << " ----> ";
for (auto j : val.second)
cout << j << " ";
cout << "\n";
}
return 0;
}
Error message
prog.cpp: In function ‘int main()’:
prog.cpp:15:21: error: ‘class std::map<long long int, std::vector<int> >’ has no member named ‘first’
cout << val.first << " ----> " ;
^
prog.cpp:16:33: error: ‘class std::map<long long int, std::vector<int> >’ has no member named ‘second’
for(auto const &j : val.second)
^