I'm writing a program to manage products, employees and bills of a restaurant in C++. But I have a problem when writing a function to read information of products from file to the Product struct. That is C2280 Error and it say something like my code is attemping to reference a deleted function. I've read for this Error in Google but I don't understand so much. This is an excerpt of my code:
struct Product
{
string productID;
string productName;
string productType;
int productPrize; //USD
};
/* function to get Products information from file */
bool readProductInformation(ifstream f, ProductList& productList)
{
if (!f.is_open()) {
cout << "Can not onpen file for reading!" << endl;
return false;
}
f >> productList.numberOfProducts;
int amount = productList.numberOfProducts;
if (amount == 0) {
f.close();
return true;
}
PNode* temp = productList.head;
for (int i = 0; i < amount; i++)
{
string str;
getline(f, str, '\n');
stringstream iss(str);
getline(iss, temp->data.productID, '-');
getline(iss, temp->data.productName, '-');
getline(iss, temp->data.productType, '-');
f >> temp->data.productPrize;
temp->next = new PNode;
temp = temp->next;
}
temp = NULL;
f.close();
return true;
}
When I create ifstream f
and productList list
and call the function again, it comes to the Error!