I think you may have to close some streams or something before writing to them. Search for examples of fstream