将一个文件中的内容 输入到数组 总是出错 那位大神帮帮忙 在线等待 谢谢了
shangpinxinxiroom[8]={{1,"苹果","2.5元/斤",10000},{2,"香蕉","3元/斤",10000},{3,"水果玉米","24.00元...
shangpinxinxi room[8]={
{1,"苹果","2.5元/斤",10000}, {2,"香蕉","3元/斤",10000},
{3,"水果玉米","24.00元/包",10000}, {4,"香椿芽","14.90元/包",10000},
{5,"鞋架","1.9元/个",10000}, {6,"电脑桌","179元/个",10000},
{7,"三叔公麻薯","1.62元/个",10000}, {8,"金丝肉松饼","0.69元/个",10000}};
ofstream fout("shangpinxinxi.txt");
if(!fout)
{
cout<<"文件打开失败"<<endl;
return 0;
}
fout<<" 序号"
<<setw(20)<<"商品名称"
<<setw(31)<<"商品单价"
<<setw(23)<<"商品数量"<<endl;
for(int i=0;i<8;i++)
fout<<setw(4)<<room[i].xuhao<<setw(20)<<room[i].name<<" **** "<<setw(20)<<room[i].danjia
<<" **** "<<setw(10)<<room[i].shuliang<<endl;
fout.close();
chakanshangpinxinxi();
shangpinxinxi a2;
a2.shanchushangpinxinxi() ;
system ("pause");
return 0;
}
已经内容输入文件了 但是再将文件内容输出到数组时 总是出错 怎么办 谢谢那位大神了 在线等待 的 展开
{1,"苹果","2.5元/斤",10000}, {2,"香蕉","3元/斤",10000},
{3,"水果玉米","24.00元/包",10000}, {4,"香椿芽","14.90元/包",10000},
{5,"鞋架","1.9元/个",10000}, {6,"电脑桌","179元/个",10000},
{7,"三叔公麻薯","1.62元/个",10000}, {8,"金丝肉松饼","0.69元/个",10000}};
ofstream fout("shangpinxinxi.txt");
if(!fout)
{
cout<<"文件打开失败"<<endl;
return 0;
}
fout<<" 序号"
<<setw(20)<<"商品名称"
<<setw(31)<<"商品单价"
<<setw(23)<<"商品数量"<<endl;
for(int i=0;i<8;i++)
fout<<setw(4)<<room[i].xuhao<<setw(20)<<room[i].name<<" **** "<<setw(20)<<room[i].danjia
<<" **** "<<setw(10)<<room[i].shuliang<<endl;
fout.close();
chakanshangpinxinxi();
shangpinxinxi a2;
a2.shanchushangpinxinxi() ;
system ("pause");
return 0;
}
已经内容输入文件了 但是再将文件内容输出到数组时 总是出错 怎么办 谢谢那位大神了 在线等待 的 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询