Note that there are some explanatory texts on larger screens.

plurals
  1. POFixing a weird write to file bug in c++
    text
    copied!<p>i got this really wierd problem, i'm writing my results to an output file, i use functions A B and C i activate them in that order, the results in the file is printed in a different order, first from A than from C and after that from B. i just can't understand why the results printed in a different order than the activation order. thanx.</p> <p>the code : </p> <pre><code>void Manager::AddCommand(Command* com, ofstream &amp;ResultFile) { if (com != NULL) { if (com-&gt;ValidCommand(ResultFile) == true) commands.push_back(com); else delete com; } } bool Command::ValidCommand(ofstream &amp;Result) const { if(func&lt;PrintCityCouncilList || func &gt;HireEmployee){ Result &lt;&lt; "Command:Failed activating function - invalid function number\n"; return false;} if ((func == Command::PrintDepartmentEmployees) || (func == Command::PrintDepartmentExpenses) || (func == Command::PrintDepartmentStatistics)){ if(dept&lt;Employee::Engineering ||dept&gt;Employee::Sanitation ) { Result &lt;&lt; "Command:Failed activating function - invalid department number\n"; return false; } } return true; } void Manager::ActivateCommand(Command* com, ofstream &amp;Result) { if(com != NULL) { switch(com-&gt;GetFunction()) { case (Command::PrintCityCouncilList): pcc-&gt;PrintCityCouncilDetails(Result); break; case (Command::PrintDepartmentEmployees):ActivatePrintDeprtEmployees(com-&gt;GetDepartment(), Result); break; case (Command::PrintEmployeeSalary):ActivateEmployeeSalary(com-&gt;GetId(), Result); break; case (Command::PrintDepartmentExpenses):ActivateDeprtExpenses(com-&gt;GetDepartment(), Result); break; case (Command::PrintCityCouncilExpenses): pcc-&gt;AllExpenses (Result); break; case (Command::PrintDepartmentStatistics):ActivateDeprtStatistics(com-&gt;GetDepartment(), Result); break; case (Command::FireEmployee): pcc-&gt;RemoveEmployeeFromCC(NULL,com-&gt;GetId(),Result); break; case (Command::HireEmployee): pcc-&gt;AddEmployeeToCC(com-&gt;GetId(),com-&gt;GetPrivateName(),com-&gt;GetSurName(),com-&gt;GetDate(),com-&gt;GetAddress(),com-&gt;GetDepartment(), com-&gt;GetStatus(),com-&gt;GetSalary(),com-&gt;GetPositionPercent(),com-&gt;GetPhoneNum(), Result); break; default:Result&lt;&lt;"Manager:Failed Activating command - invalid function"&lt;&lt;endl; break; } } } void Manager::ActivateCommandsList(ofstream &amp;Result) { Command* tmp = NULL; if (commands.empty() == false) { list&lt;Command*&gt;::iterator iter = commands.begin(); while (iter != commands.end()) { tmp = (Command*)(*iter); ActivateCommand(tmp,Result); iter++; } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload