set_newh.cpp

来自「不错书对C++/C程序员很有用的大家不要错过.」· C++ 代码 · 共 25 行

CPP
25
字号
#include <iostream.h>
#include <stdlib.h>
#include <new.h>

void no_memory(void)
 {
   cerr << "There is no more memory to allocate...\n";
   exit(0);
 }

void main(void)
 {
   char *ptr;

   set_new_handler(no_memory);

   do 
   {
     ptr = new char[10000];

     if (ptr)
       cout << "Just allocated 10,000 bytes\n";
   } while (ptr);
 }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?