views:

29

answers:

1

i'm trying to write to append data to the end of a file, and am using the seekp(streamoff off, ios_base::seekdir dir) function but it doesn't append, somehow it writes the data in the middle of the file. i tried adding opening the file like this - file.open(resultFile,fstream::in|fstream::out); (as was suggested in other similar posts) though i still get the same output. that's the code:

bool Manager::ValidCommand(Command* com, ofstream &ResultFile) const  
{  
    Employee::DepartmentEn dept = Employee::InvalidDepartment;  
       if (com == NULL)  
            return false;  
       if(com->GetFunction() <Command::PrintCityCouncilList || com->GetFunction() > Command::HireEmployee){  
            ResultFile.seekp(0,ios::end);  
            ResultFile << "Command:Failed activating function - invalid function number\n";  
            return false;}  
       if ((com->GetFunction() == Command::PrintDepartmentEmployees) || (com->GetFunction() == Command::PrintDepartmentExpenses) || (com->GetFunction() == Command::PrintDepartmentStatistics)){  
            dept = com->GetDepartment();  
       if((pcc->FindDepartment(dept) == NULL )|| (dept < Employee::Engineering) ||(dept > Employee::Sanitation))  
       {  
           ResultFile.seekp(0,ios::end);  
           ResultFile << "Command:Failed activating function - invalid department \n";  
           return false;  
       }  
   }  
   return true;  
}

what might i be doing wrong?

A: 
tommieb75
it contains a list of Departments, the function it calls is to verify whether a certain Department exists
shiran bar
@Shiran: Is that a global variable in this context?
tommieb75
it's a global variable (a field in a higher class object that was created in the main), wasn't created in this function.
shiran bar
i changed it removed the ios::in in the declaration, as well as tried what u suggested with the fail() function, though it didn't work as well
shiran bar