[C++] 纯文本查看 复制代码
#include <iostream>
#include <new>
using namespace std;
int main()
{
int *p, i;
try {
p = new int[9999999999999];
}
catch (bad_alloc xa) {
cout << "Allocation failure.\n";
return 1;
}
delete [] p;
cout << "Allocation OK, has deleted the allocated memory.\n";
return 0;
}
[C++] 纯文本查看 复制代码
#include <iostream>
#include <new>
using namespace std;
int main()
{
int *p, i;
p = new(nothrow) int[9999999999990000000000000];
if (!p) {
cout << "Allocation failure.\\n";
return 1;
}
cout << "Allocation OK.\\n";
delete [] p;
return 0;
}