简体   繁体   English

如何在 Visual Studio Code 中使用“hash_map”?

[英]How can I use 'hash_map' in Visual Studio Code?

I'm studying STL in Visual Studio Code.我正在 Visual Studio Code 中学习 STL。

I can't include 'hash_map'我不能包括'hash_map'

#include <hash_map>

So I'm using 'unordered_map' temporarily所以我暂时使用'unordered_map'

I wanna use 'hash_map'我想使用'hash_map'

There is no such header in the standard and the MSDN Documentation about <hash_map> [ 2 ] says:标准中没有这样的标题,关于<hash_map> [ 2 ] 的 MSDN 文档说:

This header is obsolete.此标头已过时。 The alternative is <unordered_map> .替代方法是<unordered_map>

You better have a good reason but the error message is very clear你最好有一个很好的理由但错误信息很清楚

c:\\program files (x86)\\microsoft visual studio\\2017\\community\\vc\\tools\\msvc\\14.12.25827\\include\\hash_map(16): fatal error C1189: #error: is deprecated and will be REMOVED. c:\\program files (x86)\\microsoft visual studio\\2017\\community\\vc\\tools\\msvc\\14.12.25827\\include\\hash_map(16): 致命错误 C1189: #error: 已弃用,将被删除。 Please use <unordered_map>.请使用 <unordered_map>。 You can define _SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS to acknowledge that you have received this warning.您可以定义 _SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS 来确认您已收到此警告。

So just do this所以就这样做

#define _SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS
#include <hash_map>

You could also add _SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS to your project properties.您还可以将_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS添加到您的项目属性中。

头文件在 c++11 中已过时,重命名为 unordered_map,参考: http : //en.cppreference.com/w/cpp/container/unordered_map

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM