My setup: macOS with Xcode/clang
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:
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?
How should I test an error_code against a known integer such as errnos?
You should compare against the std::errc
enum members that correspond to errno
integers.
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
.
std::error_code
can't be compared with an int
directly; you might want std::error_code::value
to get the value of the error_code. (And you might also need the help of category
.)
Returns the platform dependent error value.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.