0

my output formatting is wrong, here is display function below:

std::ostream &Seat::display(std::ostream &coutRef) const
    {
         if(isEmpty()){
           coutRef<<"Invalid Seat!";
       }
       //check if seat no is valid or not
       else if(!validate(m_row,m_letter)){
        char temp[41];
              strncpy(temp,m_passengerName,40);
                temp[40]='\0';
           coutRef<<temp<<setw(41-strlen(temp))<<setfill('.')<<" "<<"___";
       }
       
       else{
           char temp[41];
              strncpy(temp,m_passengerName,40);
                temp[40]='\0';
                coutRef<<temp<<setw(41-strlen(temp))<<setfill('.')<<" "<<m_row<<m_letter;

       }
        return coutRef;
    }

My output Below:

..1- Business Class Window: Baby Gerald............................. 1A
..2- Business Class  Aisle: Groundskeeper Willie.................... 1B
..3- Business Class  Aisle: Dolph Starbeam.......................... 1E
..4- Business Class Window: Kirk Van Houten......................... 1F
..5- Business Class Window: Artie Ziff.............................. 2A
..6- Business Class  Aisle: Edna Krabappel.......................... 2B
..7- Business Class  Aisle: Luann Van Houten........................ 2E
..8- Business Class Window: Janey Powell............................ 2F
..9- Business Class Window: Akira Kurosawa.......................... 3A
.10- Business Class  Aisle: Luigi Risotto........................... 3B
.11- Business Class  Aisle: Homer Simpson........................... 3E
.12- Business Class Window: Selma Bouvier........................... 3F
.13- Business Class Window: Wendell Borton.......................... 4A
.14- Business Class Middle: Manjula Nahasapeemapetilon.............. 4B
.15- Business Class Middle: Kearney Zzyzwicz........................ 4E
.16- Business Class Window: Brandine Spuckler....................... 4F
.17- Invalid seat assigned: Moe Szyslak............................. ___
.18- Invalid seat assigned: Ralph Wiggum............................ ___
.19-   Economy Plus  Aisle: Barney Gumble........................... 7D

I just want to remove dots from the front of the number like ..1, ..2, ..3 I just want to remove .. from the front. I just want to print like this 1,2,3

Jimmy S
  • 19
  • 2
  • 4
    `setfill` is "sticky" - it affects all output untill you change it again. So add a `setfill(' ')` to get spaces back. – BoP Oct 05 '22 at 17:04
  • *"`std::setfill` will "stick""* as explained [here](https://stackoverflow.com/a/30968371/12002570). Also see [Which iomanip manipulators are 'sticky'?](https://stackoverflow.com/questions/1532640/which-iomanip-manipulators-are-sticky) – Jason Oct 05 '22 at 17:17
  • @BoP exactly where I need to add setfill(' ') – Jimmy S Oct 05 '22 at 17:33
  • The posted snippet doesn't show how you print the numbers. Well, it's there. You may also find [`std::right`](https://en.cppreference.com/w/cpp/io/manip/left) and friends useful. – Bob__ Oct 05 '22 at 19:58

0 Answers0