0

I'm not sure how to go about lining this up better. I thought by using L = name.length(); and subtracting that from the setw it would line up better but nope. I have name and ID set correctly but I can't seem to get the rest to line up. These are floats btw.

for (int z=0; z<i ;z++){

  if( EInfo[z].valid >0){

    string name = employee[z].getName();
    int L = name.length();

    payReportObj << fixed << setprecision (2)  <<  endl;

      payReportObj  << setw(3) << employee[z].getID()
                  << setw(36)
                  << employee[z].getName()
                  << setw(30-L) << "$" << setw(4) << EInfo[z].grossPaySE
                  << setw(25) << "$" << setw(4) << EInfo[z].taxSE
                  << setw(15) << "$" << setw(4) << EInfo[z].insuranceSE
                  << setw(25) << "$" << setw(4) << EInfo[z].netPaySE;

I'm attempting to get it more like this... Want I'm trying to go for

This is what I have... This is what I have.

softsound
  • 29
  • 3

1 Answers1

0

Replace setw(30-L) with setw(30). And this:

int L = name.length();

is not needed. If you want to right-align numbers, use std::right.

It seams that you opened your output file in nodepad with proportional font. You won't see columns aligned with proportional font even if they are. Change font to fixed or type in your terminal type output.txt.

Leonid Volnitsky
  • 8,854
  • 5
  • 38
  • 53