0

Does C++ have predefined text constants / string constant to be used as replacements for digits when testing errorcodes ?

An example:

if (errcode == 17){
  std::cout << "The file already exists!" << std::endl;
  }

To make it more readable I can write:

 if (errcode == FILE_ALREADY_EXISTS){
   std::cout << "File already exists!" << std::endl;
   }

Of course I can define an integer constant with the name FILE_ALREADY_EXISTS and give it the value 17,
but (maybe) there are some predefined string constants / text constants defined in a standard header-file somewhere ?

2
Contributors
1
Reply
14
Views
2 Years
Discussion Span
Last Post by vijayan121
2

<cerrno> defines several standard integer error codes (integer constant expressions with type int).
For instance, ENOENT for 'No such file or directory'
http://en.cppreference.com/w/cpp/error/errno_macros

<system_error> gives us the scoped enum std::errc
For instance, std::errc::no_such_file_or_directory
http://en.cppreference.com/w/cpp/error/errc

<system_error> also has the class std::error_code. Objects of this type can be created from an error code enum and std::error_code::::message() returns a string containing the error message.
http://en.cppreference.com/w/cpp/error/error_code/message

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.