[英]Compare std::error_code with integers
My setup: macOS with Xcode/clang 我的设置:带Xcode / clang的macOS
From examples of std::error_code , it seems that it's compatible with enum, eg, you can assign an enum to it, but when comparing it with an integer like this: 从std :: error_code的例子看 ,它似乎与枚举兼容,例如,你可以为它分配一个枚举,但是当它与这样的整数比较时:
if (my_error_code == 0)
I got 我有
Invalid operands to binary expression ('const std::error_code' and 'int')
How should I test an error_code against a known integer such as errno
s? 我应该如何针对已知整数(如
errno
s)测试error_code?
How should I test an error_code against a known integer such as errnos?
我应该如何针对已知整数(如errnos)测试error_code?
You should compare against the std::errc
enum members that correspond to errno
integers. 您应该与对应于
errno
整数的std::errc
枚举成员进行比较。
If for whatever reason you can't / don't want to do that, then compare against a new error_code
constructed from the appropriate category and value
. 如果由于某种原因你不能/不想这样做,那么比较一个从适当的类别和
value
构造的新的error_code
。
std::error_code
can't be compared with an int
directly; std::error_code
无法直接与int
进行比较; you might want std::error_code::value
to get the value of the error_code. 您可能希望
std::error_code::value
获取error_code的值。 (And you might also need the help of category
.) (你可能还需要
category
的帮助。)
Returns the platform dependent error value.
返回与平台相关的错误值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.