I have the following working code which produces formatted output using an ofstream, however I feel that all of the repeated format specifiers make it hard to read. Is there any way to set the precision, width and alignment permanently for a given stream, which would clean things up nicely?
#include <fstream>
#include <iomanip>
ofstream myfile;
myfile.open(Output.c_str(), ios::trunc);
for (int i = 0; i < iLen; i++) {
myfile <<std::fixed << std::setw( iWidth ) << std::setprecision( iDecimals )<< std::right << pDist[i] << " "
<<std::fixed << std::setw( iWidth ) << std::setprecision( iDecimals )<< std::right << pRes[i] << " "
<<std::fixed << std::setw( iWidth ) << std::setprecision( iDecimals )<< std::right << pPhase[i] << "\n";
}
myfile.close();