gpt4 book ai didi

c++ - 将 std::error_code 与整数进行比较

转载 作者:行者123 更新时间:2023-11-30 02:14:30 26 4
gpt4 key购买 nike

我的设置:带有 Xcode/clang 的 macOS

来自 examples of std::error_code ,它似乎与枚举兼容,例如,您可以为其分配一个枚举,但是当它与这样的整数进行比较时:

if (my_error_code == 0)

我得到了

Invalid operands to binary expression ('const std::error_code' and 'int')

我应该如何针对已知整数(例如 errno)测试 error_code是吗?

最佳答案

std::error_code 不能直接与 int 进行比较;你可能想要 std::error_code::value获取 error_code 的值。 (您可能还需要 category 的帮助。)

Returns the platform dependent error value.

关于c++ - 将 std::error_code 与整数进行比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57743904/

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