Hi, I am reading textfiles in a structure like this:

ifstream TextFile;
 TextFile.open("quote.txt");
 while (!TextFile.eof())
 {
  TextFile >> Quote[RecordNumber].RefNumber;
  TextFile >> Quote[RecordNumber].Surname;
  TextFile >> Quote[RecordNumber].Initials;
  TextFile >> Quote[RecordNumber].TotalCost;
  TextFile >> Quote[RecordNumber].DeliveryCost;
  TextFile >> Quote[RecordNumber].Guarantee;
  TextFile >> ws;
  RecordNumber++;
 }
 TextFile.close();

However, this needs to be put into a function. I tried to do it by doing this: (the structure is defined as RecDetails Quote)

RecDetails ReadRecords (RecDetails Quote, int RecordNumber=0)
{
 ifstream TextFile;
 TextFile.open("quote.txt");
 while (!TextFile.eof())
 {
  TextFile >> Quote[RecordNumber].RefNumber;
  TextFile >> Quote[RecordNumber].Surname;
  TextFile >> Quote[RecordNumber].Initials;
  TextFile >> Quote[RecordNumber].TotalCost;
  TextFile >> Quote[RecordNumber].DeliveryCost;
  TextFile >> Quote[RecordNumber].Guarantee;
  TextFile >> ws;
  RecordNumber++;
 }
 TextFile.close();
}

However i get an error message saying "operator+ not implemented in type 'RecDetails' for arguments of type 'int'"

Any ideas what im doing wrong?

Hi, I am reading textfiles in a structure like this:

ifstream TextFile;
 TextFile.open("quote.txt");
 while (!TextFile.eof())
 {
  TextFile >> Quote[RecordNumber].RefNumber;
  TextFile >> Quote[RecordNumber].Surname;
  TextFile >> Quote[RecordNumber].Initials;
  TextFile >> Quote[RecordNumber].TotalCost;
  TextFile >> Quote[RecordNumber].DeliveryCost;
  TextFile >> Quote[RecordNumber].Guarantee;
  TextFile >> ws;
  RecordNumber++;
 }
 TextFile.close();

However, this needs to be put into a function. I tried to do it by doing this: (the structure is defined as RecDetails Quote)

RecDetails ReadRecords (RecDetails Quote, int RecordNumber=0)
{
 ifstream TextFile;
 TextFile.open("quote.txt");
 while (!TextFile.eof())
 {
  TextFile >> Quote[RecordNumber].RefNumber;
  TextFile >> Quote[RecordNumber].Surname;
  TextFile >> Quote[RecordNumber].Initials;
  TextFile >> Quote[RecordNumber].TotalCost;
  TextFile >> Quote[RecordNumber].DeliveryCost;
  TextFile >> Quote[RecordNumber].Guarantee;
  TextFile >> ws;
  RecordNumber++;
 }
 TextFile.close();
}

However i get an error message saying "operator+ not implemented in type 'RecDetails' for arguments of type 'int'"

Any ideas what im doing wrong?

The function doesn't return anything, so you need to use "void". Second, Quote will terminate once the function exits which you can extract later so you'll need to pass by reference or via pointers. I've modified the code to this:

void ReadRecords (RecDetails *Quote, int RecordNumber)
{
ifstream TextFile("quote.txt");
RecordNumber = 0;
if (TextFile.is_open) {
cout << "Error opening file quote.txt" << endl;
} else {
while (!TextFile.eof())
{
TextFile >> Quote[RecordNumber]->RefNumber;
TextFile >> Quote[RecordNumber]->Surname;
TextFile >> Quote[RecordNumber]->Initials;
TextFile >> Quote[RecordNumber]->TotalCost;
TextFile >> Quote[RecordNumber]->DeliveryCost;
TextFile >> Quote[RecordNumber]->Guarantee;
/* TextFile >> ws; - ws is not declared in the function */
RecordNumber++;
} 
TextFile.close();
}
}

Good luck, LamaBot

This question has already been answered. Start a new discussion instead.