I'm assuming you actually specify a name for the output file, e.g.
std::ofstream outputFile("some-file.txt");
Assuming this is sorted, have a look at std::setw(n)
from <iomanip>
and make sure your outputs are somehow separated. For example, you might want to use
outputFile << std::setw(8) << getAccount() << ' '
<< std::setw(20) << getName() << ' '
<< std::setw(6) << getNum1() << ' '
<< std::setw(6) << getNum2() << ' '
<< getTotal() << '\n';
... and if you really want to make sure the output is immediately written to the file rather than buffered:
outputFile << std::flush;
(which is equivalent to std::outputFile.flush();
but using cuter syntax).
Based on comments mentioned above, I would guess you ended up with names containing a '\r'
right at the end: this way, it looks as if there is nothing but actually the characters are just overwritten by characters coming later. You can remove the carriage return characters using
str.erase(std::remove(str.begin(), str.end(), '\r'), str.end());