"storing data inputted into a struct to a file".
if I have for instance: a struct of type employee,
struct employee
{
char name;
char addr;
}
Will I need to have an array to count the number of employees stored to file(ie if unsure of number of employees)! Not quite sure how to keep count of # of employees dat will b stored 2 file
Example:
____________________________________________________________
int vWriteFile ()
{
fstream employeeFile;
int iCount = 0;
//employeFile.open ("employee.bin", ios::in|ios::out|ios::binary);
if (employeeFile)
{
//unsure how to get
total # of employees
wen #of employees
is unknown
for (int i = 0; i < total employees??; i++)
{
// only write active employees to file
if (EmployeeArray[i].iStatus == ACTIVE)
{
questionFile << employeeArray[i].name << endl
<< employeeArray[i].addr << endl;
iCount++;
}
}
}
else
{
cout << "Error!" << "employeefile fail 2 open!";
}
employeeFile.close();
return iCount;
}
____________________________________________________________
Can some1 explain to me exactly, how I will be able to store employee details to file, when Im unsure how many employees will be inputted?
(Any number of employees can be inputted!)
Refer to bold comments for clarification!
Cheers
OH! and I 4Got, do I need an array? becos Im saving to a binary file, so Im unsure if an ARRAY is necessary!
Thanx for your help!
This post has been edited by skyhawk133: 06 June 2005 - 04:57 PM

New Topic/Question
Reply



MultiQuote




|