MyBlog
ariesjzj
全部博文(55)
2011年(2)
2010年(7)
2009年(17)
2008年(29)
songchua
penguin2
jackie_i
nelson_x
cpk1ng
muyuran
szchl200
hweired
倔强的土
分类: C/C++
2008-08-22 02:03:10
#include <iostream>#include <exception>using namespace std;int main () throw ( exception ) { const unsigned long SIZE = 500000000; char *ptr[10]; try { for ( int counter = 0; counter < 10; counter++ ) { ptr[counter] = new char[SIZE]; cout << "Memory for ptr[" << counter << "] is allocated" << endl; } } catch (exception &e) // catch ( ... ) { cout << "Exception: "; cout << e.what() << endl; return 1; } for ( int i = 0; i < 10; i++ ) delete [] ptr[i]; cout << "End" << endl; return 0;}OUTPUT:// Memory for ptr[0] is allocated// Memory for ptr[1] is allocated// Memory for ptr[2] is allocated// Memory for ptr[3] is allocated// Memory for ptr[4] is allocated// Exception: bad_alloc
上一篇:Qt的绘图系统
下一篇:一些好玩的字
登录 注册