0

When using

unordered_map<int,int> mp;

or

unordered_set<int> s;

,I am getting the following error on mac :

error: no template named 'unordered_map'

Output for gcc --version :

Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 12.0.0 (clang-1200.0.32.29)
Target: x86_64-apple-darwin20.4.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

Code :

#include<bits/stdc++.h>
using namespace std;


int main(){
    unordered_map<int,int> mp;
    mp[1] = 2;
    return 0;
}
Pradeep
  • 3
  • 2
  • 3
    `-std=c++11` is required. gcc is an alias for clang, and it defaults to C++98 on a mac. – sweenish May 22 '21 at 09:37
  • gcc doesn't have that. – EL_9 May 22 '21 at 09:37
  • 1
    *That*, being what exactly? – sweenish May 22 '21 at 09:38
  • You're going to have to show some code if the compiler flag doesn't fix the issue. You're supposed to read [ask] and [mre] at a minimum before posting your first question. – sweenish May 22 '21 at 09:40
  • @sweenish , I am novice so couldn't get it. What exactly should I do? Also, the code is just a simple line in main (update in the question) – Pradeep May 22 '21 at 10:13
  • My first comment is a compiler flag. At a minimum, your compile command should be `clang++ -Wall -Wextra -std=c++11 `. I will also say that wherever you're learning from, stop and find a [good book](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) instead. Your first line is implementation-dependent (not good), and your second line is bad practice. – sweenish May 22 '21 at 10:20
  • 1
    thank you @sweenish for the resource. By the way, the code worked when I included unordered_map header instead of bits/stdc++.h. Thanks for the suggestion – Pradeep May 22 '21 at 10:36

0 Answers0