Hi everyone, i am a student of IT and i am trying to read a text file and load it into a records of nested structs. I understand the logic how to do it, but i had a few problems.
the txt. file contains :
John Smith
125 2004
Daily News,76
New Mail,159
English news,244
The Mercury,342
<< moderator edit: added code tags: [code][/code] >>
my definition of structs are
struct annualSalesData
{
int numVendors, year;
vendorData *vendors;
};
struct vendorData
{
char name[MAX_VENDOR_NAME_SIZE];
dailySalesData sales[MAX_DAILY_SALES];
};
struct dailySalesData
{
int day;
int papers[NUM_NEWSPAPERS];
};
DailySalesData is nested into the vendorData and VendorData is nested into
annualSalesData ( with a pointer to this struct )
my code was:
/create the stream object
ifstream myFile;
//connect it with the file
myFile.open( fileName.c_str(), ios::in );
//check if it works
if ( !myFile.good() )
{
cerr << "ERROR: Unable to open file " << fileName << endl;
return false;
}
// case positive read data
//try to read fist entry
myFile.seekg ( sales.vendors[sales.numVendors].name * sizeof (annualSalesData ), ios::end );
// close file
myFile.close();
return true;
} //end of function load text file for Update vendors
i tried to use the stream >> <<
as :
myFile >> sales.vendors[sales.numVendors].name;
... etc
But it does not work either...
if anyone can help me with some directions on how to do load the file into de records struct. Any help will be sincerely appreciate it. Or any examples of how to read data into nested structs would be great. Thanks so much!
regards