##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# std::strerror

From cppreference.com
< cpp‎ | string‎ | byte

Defined in header `<cstring>` |  |
char* strerror( int errnum ); |  |

Returns text version of the error code `errnum`. `errnum` is usually acquired from the `errno` variable, however the function accepts any value of type int. The message is locale-specific.

The returned byte string must not be modified by the program, but may be overwritten by a subsequent call to the `strerror` function.

### [edit] Parameters

errnum | - | integral value referring to a error code

### [edit] Return value

Pointer to a null-terminated byte string corresponding to the error code `errnum`.

### [edit] Example

Run this code

    #include <iostream>
    #include <cmath>
    #include <cerrno>
    #include <cstring>

    int main()
    {
        double not_a_number = std::log(-1.0);
        if (errno == EDOM) {
            std::cout << "log(-1) failed: " << std::strerror(errno) << '\n';
        }
    }

Output:

    log(-1) failed: Numerical argument out of domain

### [edit] See also

E2BIG, EACCES, ..., EXDEV | macros for standard POSIX-compatible error conditions (macro constant) [edit]
C documentation for strerror

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/string/byte/strerror&oldid=59009"