Whenever I try to use maps in VS Code, on compilation, it shows ‘unordered_map’ was not declared in this scope
How can I solve this?
Can you share the code, you were writing?
make sure you have included statement
#include <unordered_map>
unordered_map is not included in map and so you have to separately include it.
I used #include<bits/stdc++.h>, it should cover it
When I included unordered_map separately, it is showing This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
#include <bits/stdc++.h>
#define ll int
#define MOD 1e9+7
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define sep(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define pb push_back
#define db double
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
#define sz(a) (ll)a.size()
#define Frs first
#define Snd second
#define quick ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
void solve() {
ll n;
cin>>n;
vector <int> arr(n,0);
vector <int> temp(n,0);
rep(i,0,n) {
cin>>arr[i];
temp[i] = arr[i];
}
sort(all(temp), greater<int>());
unordered_map <int, int> mp;
rep(i,0,n) {
if (mp.find(temp[i]) == mp.end())
mp.insert({temp[i], i+1});
}
rep(i,0,n) {
if (mp[arr[i]]>0) {
cout<<mp[arr[i]]<<" ";
mp[arr[i]]*=-1;
}
else {
cout<<abs(mp[arr[i]])+1<<" ";
mp[arr[i]]--;
}
}
cout<<endl;
}
int main()
{quick;
ll t;
cin>>t;
while(t--) {
solve();
}
return 0;
}
This was the code I was trying to run.
Working fine in Dev-C++
Yeah, it’s working in other editors, only showing error in Visual Studio Code editor
Hi,
There are 2 things you can do:
- Visual Studio by default does not have the bits stdc++ file available. So you can add a new file and add it to the path of visual studio.
- You can include unordered map and then use -std=c++11 flag when compiling.
But yeah the 1st approach will be very helpful in general in keeping your code concise and not worrying about imports.
Some references:
- Windows (solution to include bits/stdc++.h in Visual Studio 2019 - Codeforces)
- Mac (How to include bits/stdc++.h header file on macOS - Codeforces) (I have tried this on my mac and it helped me, so I am able to answer this.