set_newh.cpp

来自「C/C++使用技巧1001例一书的配套代码」· C++ 代码 · 共 24 行

CPP
24
字号
#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 + -
显示快捷键?