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 ?

<cerrno> defines several standard integer error codes (integer constant expressions with type int).
For instance, ENOENT for 'No such file or directory'

<system_error> gives us the scoped enum std::errc
For instance, std::errc::no_such_file_or_directory

<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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.