2013-03-21 57 views
5

我試圖用的hash_map,在Android NDK定義,但我得到一個 「棄用警告」:如何在Android中使用unordered_map?

ndk/sources/cxx-stl/gnu-libstdc++/4.6/include/ext/../backward/backward_warning.h:33:2: 
error: #warning This file includes at least one deprecated or antiquated header which may 
be removed without further notice at a future date. Please use a non-deprecated interface 
with equivalent functionality instead. For a listing of replacement headers and 
interfaces, consult the file backward_warning.h. To disable this warning use -Wno- 
deprecated. [-Werror=cpp] 

而且,由於 「unordered_map」 存在於GNU-的libstdC++/4.6 /包括/和也在gnu-libstdC++/4.6/include/tr1 /中,我相信有一種方法可以使用它。

問題是我找不到它。以下哪一項是正確的(如果有的話):

#include <tr1/unordered_map.h> 

#include <unordered_map> 

然後,如何使用它? __gnu_cxx :: unordered_map無法識別...我不知道如何找到這些信息。

回答

2

我最終在Android項目中添加了C++ 11支持。當我們知道時很容易,但我花了一些時間來弄清楚。 STLPort和Boost都不需要。一旦C++ 11集成的,我可以用 「unordered_map」 如下:

#include <unordered_map> 
... 
std::unordered_map<int, int> test; 

我創建了一個新的問題,解釋瞭如何啓用的Android here C++ 11的支持。

5

如果你不想/需要C++ 11的支持,您可以使用使用來自STLPort的一個:

// Here we are referencing the stlport one: 
#include <unordered_map> 
... 
std::tr1::unordered_map<int, int> test; 

這是因爲STLPort的定義unordered_mapTR1命名空間,但是STLPort標頭不在任何/tr1/文件夾內。