| Localization library | |||||||||||||||||||||||||
| Regular expressions library(C++11) | |||||||||||||||||||||||||
| Formatting library(C++20) | |||||||||||||||||||||||||
| Null-terminated sequence utilities | |||||||||||||||||||||||||
| Byte strings | |||||||||||||||||||||||||
| Multibyte strings | |||||||||||||||||||||||||
| Wide strings | |||||||||||||||||||||||||
| Primitive numeric conversions | |||||||||||||||||||||||||
| |||||||||||||||||||||||||
| Text encoding identifications | |||||||||||||||||||||||||
| |||||||||||||||||||||||||
| Functions | ||||||||||||||||||||||||||||||||||||
| Character classification | ||||||||||||||||||||||||||||||||||||
| Character manipulation | ||||||||||||||||||||||||||||||||||||
| Conversions to numeric formats | ||||||||||||||||||||||||||||||||||||
|
| |||||||||||||||||||||||||||||||||||
| String manipulation | ||||||||||||||||||||||||||||||||||||
| String examination | ||||||||||||||||||||||||||||||||||||
| Character array functions | ||||||||||||||||||||||||||||||||||||
| Miscellaneous | ||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||
Defined in header <cstring> | ||
char* strerror(int errnum); | ||
Returns a pointer to the textual description of the system error codeerrnum, identical to the description that would be printed bystd::perror().
errnum is usually acquired from theerrno variable, however the function accepts any value of typeint. The contents of the string are locale-specific.
The returned string must not be modified by the program, but may be overwritten by a subsequent call to thestrerror function.strerror is not required to be thread-safe. Implementations may be returning different pointers to static read-only string literals or may be returning the same pointer over and over, pointing at a static buffer in whichstrerror places the string.
Contents |
| errnum | - | integer value referring to an error code |
Pointer to a null-terminated byte string corresponding to theerrno error codeerrnum.
POSIX allows subsequent calls tostrerror to invalidate the pointer value returned by an earlier call. It also specifies that it is theLC_MESSAGES locale facet that controls the contents of these messages.
POSIX has a thread-safe version calledstrerror_r defined. Glibcdefines an incompatible version.
#include <cerrno>#include <clocale>#include <cmath>#include <cstring>#include <iostream> int main(){constdouble not_a_number=std::log(-1.0);std::cout<< not_a_number<<'\n'; if(errno==EDOM){std::cout<<"log(-1) failed: "<< std::strerror(errno)<<'\n';std::setlocale(LC_MESSAGES,"de_DE.utf8");std::cout<<"Or, in German, "<< std::strerror(errno)<<'\n';}}
Possible output:
nanlog(-1) failed: Numerical argument out of domainOr, in German, Das numerische Argument ist ausserhalb des Definitionsbereiches
| displays a character string corresponding of the current error tostderr (function)[edit] | |
| macros for standard POSIX-compatible error conditions (macro constant)[edit] | |
C documentation forstrerror | |