gpt4 book ai didi

c++ - 是什么导致 hash_map 错误,我该如何解决?

转载 作者:太空宇宙 更新时间:2023-11-03 17:25:02 25 4
gpt4 key购买 nike

我正在尝试编译并运行此 GUI 代码:

#include "Simple_window.h" // Get access to our window library
#include "Graph.h" // Get access to our graphics library facilities

int main()
{
using namespace Graph_lib; // Our graphics facilities are in Graph_lib
Point tl{ 100, 100 }; // To become top left corner of window
Simple_window win{ tl, 600, 400, "Canvas" }; // Make a simple window
Polygon poly; // Make a shape (a polygon)
poly.add(Point{ 300, 200 }); // Add a point
poly.add(Point{ 350, 100 }); // Add another point
poly.add(Point{ 400, 200 }); // Add a third point
poly.set_color(Color::red); // Adjust properties of poly
win.attach(poly); // Connect poly to the window
win.wait_for_button(); // Give control to the display engine
}

header 和代码文件的来源:http://www.stroustrup.com/Programming/PPP2code/

我收到 hash_map 错误

Error (active)    E0035    #error directive: <hash_map> is deprecated and will be REMOVED. Please use <unordered_map>. You can define _SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS to acknowledge that you have received this warning.    ConsoleApplication1    C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.24.28314\include\hash_map    21

是什么导致了 hash_map 错误,我该如何解决?

最佳答案

这正是它所说的。

header <hash_map>不是标准的,但是 came from the actual STL .虽然 it currently remains available on your platform ,它“已弃用并将被删除”。

您应该按照消息中的说明进行操作并切换到现代工具,例如 std::unordered_map .不幸的是,这意味着偏离您的原始资料。

我猜测错误本身来自于 fltk(Bjarne 的代码似乎都没有包含该 header ,尽管我只是快速扫描了它)。这些例子非常非常古老。

你可以从a modern book学习C++ , 而不是。

与此同时,如错误消息所述,您可以定义 _SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS (在“预处理器定义”下的项目设置中)暂时确认这一点。


类似问题:

关于c++ - 是什么导致 hash_map 错误,我该如何解决?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59582015/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com