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?