|
楼主 |
发表于 2020-3-2 16:45:01
|
显示全部楼层
代码:
ifstream in_stream;
in_stream.open("进货库.txt");
if(in_stream.fail())
{
cout<<"Opening file fail 1111!"<<endl;
exit(1); //异常退出
}
string strtemp;
int i;
string strGoodsName; //货名
string strModelNum; //商品型号
string strGoodsNum; //货号
int nCount; //商品数量
double dwPrice; //商品进货价格(单价)
double dwProfits; //商品利润()
string strProvider; //供货商
string strManName; //经办人
//下面是初始化进货库
in_stream.seekg(0,ios::beg);
for(i=0;i<8;i++)
in_stream>>strtemp; //将第一行忽略掉
for(i=0;i<12;i++) //正式读取内容
{
in_stream>>strGoodsName>>strModelNum>>strGoodsNum>>nCount>>dwPrice
>>dwProfits>>strProvider>>strManName;
m_InWareHouse.Add(CMerchandise(strGoodsName,strModelNum,strGoodsNum,nCount,
dwPrice, dwProfits,strProvider,strManName));
}
in_stream.close();
//下面是初始化库存
in_stream.open("库存.txt");
if(in_stream.fail())
{
cout<<"Opening file fail 2222!"<<endl;
exit(1); //异常退出
}
in_stream.seekg(0,ios::beg);
for(i=0;i<7;i++)
in_stream>>strtemp; //将第一行忽略掉
for(i=0;i<12;i++) //正式读取内容
{
in_stream>>strGoodsName>>strModelNum>>strGoodsNum>>nCount>>dwPrice
>>dwProfits>>strProvider;
m_InWareHouse.Add(CMerchandise(strGoodsName,strModelNum,strGoodsNum,nCount,
dwPrice, dwProfits,strProvider," "));
}
in_stream.close();
//下面是初始化销售库
in_stream.open("销售库.txt");
if(in_stream.fail())
{
cout<<"Opening file fail 3333!"<<endl;
exit(1); //异常退出
}
in_stream.seekg(0,ios::beg);
for(i=0;i<7;i++)
in_stream>>strtemp; //将第一行忽略掉
for(i=0;i<12;i++) //正式读取内容
{
in_stream>>strGoodsName>>strModelNum>>strGoodsNum>>nCount>>dwPrice
>>dwProfits>>strProvider;
m_InWareHouse.Add(CMerchandise(strGoodsName,strModelNum,strGoodsNum,nCount,
dwPrice, dwProfits,strProvider,""));
}
in_stream.close();
基本代码就是上面的,运行结果是显示 “Opening file fail 3333!” |
|