C Standard Libraries C++

perror()

Declaration

void perror(const char* kcpString);

Description

This function outputs the string "kcpString" to the stream "stderr" for error reporting. The output is the string "kcpString," followed by a colon, and then the last system error message. The last error is stored in the variable errno.

Example

#include <cstdio>

int main()
{
    char* cpFileName = "XoaX.net";
    // Try to open a file that doesn't exist
    FILE* qpFile = fopen(cpFileName, "r" );

    // Check that the file was opened successfully.
    if (!qpFile) {
        perror("Could not open the file");
        return 1;
    }

    fclose(qpFile);

    return 0;
}

Output

perror() Output
 

© 2007–2024 XoaX.net LLC. All rights reserved.