C Standard Libraries C++

abort()

Declaration

void abort();

Description

Immediately aborts the process and returns an exit code of 3.

Example

#include <iostream>
#include <fstream>
#include <cstdlib>

int main() {
    using namespace std;

    ofstream qOutFile("OutFile.txt");
    // Deliberately close the file just to test the error condition
    qOutFile.close();
    if (!qOutFile.is_open()) {
        cerr << "File \"OutFile.txt\" could not be opened." << endl;
        abort();
    }
    return 0;
}

Output

abort() Output
 

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