且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何修复“<hash_map>已弃用,将被删除.请使用<unordered_map>>"?

更新时间:2023-12-05 10:40:22

有几种方法可以修复它.您可以通过编写

There are several ways to fix it. You could just have the compiler ignore it in visual studio by writing

#define _SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS 1

在他的头文件的顶部(你可能会在他的系列的其余部分没问题).

at the top of his header file (and you'll likely be fine for the rest of his series).

您也可以将他的标头重写为使用 unordered_map 代替 hash_map.我不推荐这个,因为你是编程新手,但是 Stack Overflow 上的一些好心人可能会为你做这件事,你可以复制它(应该不难).T.C.在您帖子的评论部分此处找到了它.

You could also rewrite his header to instead of hash_map use unordered_map. I do not recommend this since you are new to programming, but some kind soul on Stack Overflow may do that for you and you can copy it (shouldn't be hard at all). T.C. has found it here in the comments section of your post.

最后,您可以为本书中的任何单元包含必要的头文件,并根据需要手动编写他正在使用的任何函数.在这种情况下,要访问 cout 函数,您需要在文件顶部写入 #include ,然后在 using namespace std; 之前写入 代码>int main().或者,您可以编写 std::cout <<"Hello World!"; 不包括using namespace std;,就是这样.最终产品看起来像:

Lastly, you could just include the necessary header files for whatever unit you are doing in the book, and manually write whatever functions he is using as you need them. In this case to access the cout function you need to write #include <iostream> at the top of your file, and then also write using namespace std; before your int main(). Alternatively, you could write std::cout << "Hello World!"; without including using namespace std;, that's all it does. The final product would look like:

#include <iostream>  //for learning, it's probably better to know what each header file does before you use it. silly book.
using namespace std; //act like std:: is before function calls from that library
int main()                             //C++ programs start by executing the function main
{
    cout <<"Hello, World!
";   //output "Hello, World!"
    cin.get();         //wait for a return character to be entered
    return 0;
}

看看你是如何开始在 Stack Overflow 上发帖的,并且可能有很高的学习 C++ 的天赋,我建议你做后者,并在你到达他的书中和之后尝试看看他的函数在做什么在互联网上快速搜索你想学习的任何很酷的东西.

Seeing as to how you are posting on Stack Overflow to begin with and probably have a high aptitude for learning C++, I recommend doing the latter and trying to see exactly what his functions are doing once you get there in his book and afterwards doing a quick search on the internet for whatever cool things you want to learn.