偶然碰到cerr
char (*c)[5];
try { c = new char [n][5];}
catch (xalloc) {//仅当new失败时才会进入
cerr << "Out of Memory" << endl;
exit (1);}
本文演示了在C++中如何使用new进行动态内存分配,并通过try-catch块捕获异常来处理内存分配失败的情况。当new操作失败时,会抛出异常并输出提示信息,确保程序不会因内存不足而陷入不确定状态。
偶然碰到cerr
char (*c)[5];
try { c = new char [n][5];}
catch (xalloc) {//仅当new失败时才会进入
cerr << "Out of Memory" << endl;
exit (1);}
1452

被折叠的 条评论
为什么被折叠?