std::atexit函数用来注册当程序终止时,调用的函数吗,通常用来释放资源。例如:
#include "stdafx.h"
#include <Windows.h>
int* ptrq = NULL;
void Release()
{
printf("release");
free(ptrq);
ptrq = NULL;
}
int _tmain(int argc, _TCHAR* argv[])
{
ptrq = (int*)malloc(sizeof(int) * 1);
atexit(Release);
exit(0);
HANDLE hConsole = GetStdHandle(STD_ERROR_HANDLE);
SetConsoleTextAttribute(hConsole, FOREGROUND_RED);
printf("hello world/n");
return 0;
}