I am having trouble reading data from a file into a list in a class. It seems like an extra hexadecimal value is being picked up somewhere.
Data: (what I want output to look like)

Output: (extra 0x4463c4 is randomly included)

Here is a bit of code i think is relevant. Can anyone advise me of errors I may have made?
Where data is read into program from file (main):
struct filmType
{
char number[6];
char copy;
char title[31];
char rent_id[5];
char rent_date[9];
char return_date[9];
};
orderedList <filmType> orderedList;
filmType newItem;
//start of struct record
filmFile.open("films.txt", ios::in);
filmFile >> numFilm;
filmFile.get();
while (!filmFile.eof())
{
filmData.copy = filmFile.get();
readString(filmFile, newItem.title,30);
readString(filmFile, newItem.rent_id,4);
readString(filmFile, newItem.rent_date,8);
readString(filmFile, newItem.return_date,8);
filmFile.get();
orderedList.insert (newItem);
readString(filmFile, filmData.number,5);
}
orderedlist.insert function:(fills list in class)
void orderedList<elemType>::insert(const elemType& newItem)
{
int index = length - 1;
bool found = false;
if (length == MAX_LIST)
throw string ("List full - no insertion");
// index of rear is current value of length
while (! found && index >= 0)
if (newItem < list[index])
{
list[index + 1] = list [index]; // move item down
--index;
}
else
found = true;
list [index + 1] = newItem; // insert new item
++length;
}
Orderedlist.display function: (outputs list to console)
void orderedList<elemType>::display() const
{
int index;
if (length == 0)
throw string ("List empty");
for (index = 0; index < length; ++ index)
cout << list[index] << endl;
}
readString:
void readString (fstream & inFile, char * string, int length)
{
inFile.get (string, length + 1);
}
Any help is appreciated, let me know if anything needs to be clarified or if more code from the program needs to be seen. Thanks!
You’re passing structs objects to cout, which doesn’t know how to display them. The hex values you get are your structs objects addresses.