谁知道哪出错了?

cd99 2004-03-28 04:25:11
#include <iostream.h>
#include <new.h>
//using std::bad_alloc;

int main()
{
double *ptr[50];

try{
for(int i=0;i<50;i++)
{
ptr[i]=new double[5000000];
cout<<"allocated 5000000 doubles in ptr["<<i<<"]\n";
}

}

catch(bad_alloc exception)
{
cout<<"excetion occurred:"
<<exception.what()<<endl;
}

return 0;
}

这个异常处理的问题我在编译是说有4个错,实在不知道哪错了?请各位指教。
...全文
49 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
rorot 2004-03-28
  • 打赏
  • 举报
回复
不用就加上.h
heavenchang 2004-03-28
  • 打赏
  • 举报
回复
就这样
都说过了
heavenchang 2004-03-28
  • 打赏
  • 举报
回复
#include <iostream>
#include <new.h>
using namespace std;

int main()
{
double *ptr[50];

try{
for(int i=0;i<50;i++)
{
ptr[i]=new double[5000000];
cout<<"allocated 5000000 doubles in ptr["<<i<<"]\n";
}

}

catch(bad_alloc exception)
{
cout<<"excetion occurred:"
<<exception.what()<<endl;
}

return 0;
}
cd99 2004-03-28
  • 打赏
  • 举报
回复
不用using namespace std;这句行吗?
RookieStar 2004-03-28
  • 打赏
  • 举报
回复
#include <iostream>
#include <new>
using namespace std;

int main()
{
double *ptr[50];

try{
for(int i=0;i<50;i++)
{
ptr[i]=new double[5000000];
cout<<"allocated 5000000 doubles in ptr["<<i<<"]\n";
}

}

catch(bad_alloc exception)
{
cout<<"excetion occurred:"
<<exception.what()<<endl;
}

return 0;
}

改成这样就好了!用namespace std时用不带.h的那种.
csumck 2004-03-28
  • 打赏
  • 举报
回复
我编译了一下,没有错!
应该是宁其他地方的错误

64,644

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧