2

I need to use a .cpp file which contains #include <unordered_map> in a Qt project (Based on Qt 5.4.2 (Clang 6.0 (Apple), 64 bit)). However, I got the error: 'unordered_map' file not found. I had checked the path of the folder where unordered_map header file locates is the same as <algorithm>, <utility>, <iostream>, and <sstream> which are included in the beginning of the same .cpp file. Only 'unordered_map' cannot be found. Any suggestion?

Kuba hasn't forgotten Monica
  • 88,505
  • 13
  • 129
  • 275
iik
  • 43
  • 1
  • 9
  • 2
    Have you enabled C++11 (or later)? If there's no checkbox in the project settings, manually add the flag `-std=c++11`. – Some programmer dude Aug 29 '15 at 16:04
  • look if https://stackoverflow.com/questions/26233011/what-could-cause-clang-to-not-find-the-unordered-map-header can solve your problem – gengisdave Aug 29 '15 at 16:05
  • Qt provides [QHash](http://doc.qt.io/qt-5/qhash.html#details), I would use it instead `unordered_map`. – Marek R Aug 29 '15 at 17:10

2 Answers2

1

The std::unordered_map template class was added in C++11, so you are probably not compiling with C++11 support. This is especially true considering that <algorithm>, <utility>, <iostream> and <sstream> work just fine (which all existed before C++11).

Simply add the -std=c++11 flag while compiling.

Shoe
  • 70,092
  • 30
  • 150
  • 251
1

Addconfig +=c++11 in pro file

You can refer this.

Community
  • 1
  • 1
Swapnil
  • 1,270
  • 13
  • 28