在C和C++中,exit()和之间有什么区别abort()?我试图在错误后结束我的程序(不是例外).
考虑以下C++程序:
#include <cstdlib> // for exit(3)
#include <string>
#include <iostream>
using namespace std;
void die()
{
exit(0);
}
int main()
{
string s("Hello, World!");
cout << s << endl;
die();
}
Run Code Online (Sandbox Code Playgroud)
通过valgrind运行这个显示了这个(一些输出为了简洁而修剪):
==1643== HEAP SUMMARY:
==1643== in use at exit: 26 bytes in 1 blocks
==1643== total heap usage: 1 allocs, 0 frees, 26 bytes allocated
==1643==
==1643== LEAK SUMMARY:
==1643== definitely lost: 0 bytes in 0 blocks
==1643== indirectly lost: 0 bytes in 0 blocks
==1643== possibly lost: 26 …Run Code Online (Sandbox Code Playgroud)