I know we can use
perror()
in C to print errors. I was just wondering if there is a C++ alternative to this, or whether I have to include
You could use the boost::system_error::error_code class.
#include
#include
#include
void
PrintError(
const std::string& message,
int error
)
{
std::cerr << message << ": " <<
boost::system::error_code(
error,
boost::system::get_system_category()
).message()
<< std::endl;
}
int
main()
{
PrintError( "something went wrong!", EINVAL );
return 0;
}
it's a tad verbose, and somewhat overkill if you aren't already using the boost_system library.