i need to read data from my txt file and iv got another function to print, but something must be wrong with my read function b/c my values turn out to be random negatives
read function
Code:
int read(Item Itemlist[], string filename)
{
int i=0;
ifstream infile( filename.c_str() );
while( !infile.eof())
{
cout << "read file" <<endl;
infile>>Itemlist[i].ID;
infile>>Itemlist[i].sold;
infile>>Itemlist[i].rem;
i++;
}
return i;
}
and the class
Code:
class Item
{
public:
string ID;
int rem;
int sold;
};
a piece of main
Code:
Item myArray[100];
int numOfRecs=read( myArray, "inventory (1).txt");
I'm almost sure it the problem isn't my print function.