|
Code:
ifstream in_stream;
in_stream.open ("stock library.txt");
if (in_stream.fail ())
{
cout << "Opening file fail 1111!" << endl;
exit (1); // Exit abnormally
}
string strtemp;
int i;
string strGoodsName; // Item name
string strModelNum; // Product model
string strGoodsNum; // Article number
int nCount; // Number of products
double dwPrice; // commodity purchase price (unit price)
double dwProfits; // commodity profit ()
string strProvider; // provider
string strManName; // Operator
// The following is the initial purchase warehouse
in_stream.seekg (0, ios :: beg);
for (i = 0; i <8; i ++)
in_stream >> strtemp; // Ignore the first line
for (i = 0; i <12; i ++) // Read the content formally
{
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 ();
// The following is the initialization inventory
in_stream.open ("Inventory.txt");
if (in_stream.fail ())
{
cout << "Opening file fail 2222!" << endl;
exit (1); // Exit abnormally
}
in_stream.seekg (0, ios :: beg);
for (i = 0; i <7; i ++)
in_stream >> strtemp; // Ignore the first line
for (i = 0; i <12; i ++) // Read the content formally
{
in_stream >> strGoodsName >> strModelNum >> strGoodsNum >> nCount >> dwPrice
>> dwProfits >> strProvider;
m_InWareHouse.Add (CMerchandise (strGoodsName, strModelNum, strGoodsNum, nCount,
dwPrice, dwProfits, strProvider, ""));
}
in_stream.close ();
// The following is the initialization sales library
in_stream.open ("sales library.txt");
if (in_stream.fail ())
{
cout << "Opening file fail 3333!" << endl;
exit (1); // Exit abnormally
}
in_stream.seekg (0, ios :: beg);
for (i = 0; i <7; i ++)
in_stream >> strtemp; // Ignore the first line
for (i = 0; i <12; i ++) // Read the content formally
{
in_stream >> strGoodsName >> strModelNum >> strGoodsNum >> nCount >> dwPrice
>> dwProfits >> strProvider;
m_InWareHouse.Add (CMerchandise (strGoodsName, strModelNum, strGoodsNum, nCount,
dwPrice, dwProfits, strProvider, ""));
}
in_stream.close ();
The basic code is the above, and the result is "Opening file fail 3333!" |
|