【发布时间】:2014-05-29 05:12:31
【问题描述】:
这是我写入文件的地方 ->
void Supermarket_Billing_System::Add_and_WriteNewProduct(Product P)
{
ofstream fl;
fl.open("ProductList", ios::out | ios::binary);
fl.write((char *) &P, sizeof(P));
fl.close();
}
这是我从文件中读取的地方 ->
void Supermarket_Billing_System::Read_DisplayProductFromProductList()
{
Product P;
int x;
ifstream fp;
fp.open("ProductList", ios::in);
fp.seekg(0, ios::beg);
fp.read((char *) &P, sizeof(P));
x = P.GetProduct_qty();
fp.close();
}
产品类看起来像这样 ->
class Product
{
private:
long int Product_no;
std::string Product_name;
double Product_price;
int Product_qty;
double Product_tax;
double Product_dis;
public:
//Constructor
Product();
Product(long int, string, double, int, double, double);
//All Getters methods
long int GetProduct_no();
string GetProduct_name();
double GetProduct_price();
int GetProduct_qty();
double GetProduct_tax();
double GetProduct_dis();
//All Setters methods
void SetProduct_no(long int);
void SetProduct_name(string);
void SetProduct_price(double);
void SetProduct_qty(int);
void SetProduct_tax(double);
void SetProduct_dis(double);
void Accept_Product();
void Accept_ProductForBilling();
void Display_Product();
};
当我尝试通过调用 Read_DisplayProductFromProductList() 从文件中读取时,它给了我错误 ->
Supermarket_Billing_System.exe 中 0x6803ad54 (msvcp100d.dll) 处的未处理异常:0xC0000005:访问冲突写入位置 0xfeeefeee。
【问题讨论】:
标签: c++ visual-c++