qq_21918325 2015-05-25 10:35 采纳率: 0%
浏览 1944

程序没错误没错误,可是运行不了

#include
#include
#include
using namespace std;
class work
{
public:
work(int n,string nam,int a,float wa)
{
num=n;name=nam;a=age;wag=wa;
}
friend ostream &operator <<(ostream &output,work &d)
{
output<<"号码:"<<d.num<<"姓名:"<<d.name<<"年龄:"<<d.age<<"工资:"<<d.wag;
return output;
}
protected:
int num,age;
string name;
float wag;
};
int main()
{
work data[5]={
work(1,"dongdong",21,5000),
work(2,"tongtong",21,4000),
work(3,"wenwen",2,50),
work(4,"huimei",23,3500),
work(5,"pingping",24,4000)
};
ofstream outfile("worker.dat");
if(!outfile)
{
cerr<<"open erreo!1"<<endl;
abort();
}
for(int i;i<5;i++)
outfile<<data[i]<<" "<<endl;
outfile.close();
return 0;
}

  • 写回答

9条回答

  • threenewbee 2015-05-25 10:44
    关注

    for(int i;i<5;i++)
    这里没有给i初始值,编译都编译不过。还说没错误。

    评论

报告相同问题?

悬赏问题

  • ¥15 luckysheet
  • ¥25 关于##爬虫##的问题,如何解决?:
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题