dimanche 1 mars 2020

How to properly use setw() to format output?

I am trying to format my output as:

1 [tab] First Name: John [tab] Last Name: Smith [tab] Age: 20 [tab]daysInCourse: {35, 40, 55} Degree Program: Security

My current code is:

{
    cout << left << setw(15) << studentID;
    cout << left << setw(15) << "First Name: " << FN;
    cout << left << setw(15) << "Last Name: " << LN;
    cout << left << setw(15) << "Email " << studentEmail;
    cout << left << setw(15) << "Age: " << age;
    cout << left << setw(15) << "{" << days[0] << ", " << days[1] << ", " << days[2];
    cout << left << setw(15) << "Degree Program: ";
}

Which outputs:

A3             First Name:    JackLast Name:     NapoliEmail          The_lawyer99yahoo.comAge:           19{              20, 40, 33Degree Program: SOFTWARE
A4             First Name:    ErinLast Name:     BlackEmail          Erin.black@comcast.netAge:           22{              50, 58, 40Degree Program: SECURITY
A5             First Name:    AndLast Name:     LootEmail          altt@wgu.eduAge:           27{              1, 2, 3Degree Program: SOFTWARE
A1             First Name:    JohnLast Name:     SmithEmail          John1989@gm ail.comAge:           20{              30, 35, 40Degree Program: SECURITY
A2             First Name:    SuzanLast Name:     EricksonEmail          Erickson_1990@gmailcomAge:           19{              50, 30, 40Degree Program: NETWORKING
A5             First Name:    AndLast Name:     LootEmail          altt@wgu.eduAge:           27{              1, 2, 3Degree Program: SOFTWARE
A4             First Name:    ErinLast Name:     BlackEmail          Erin.black@comcast.netAge:           22{              50, 58, 40Degree Program: SECURITY

I have played around with each row's setw value and cant seem to get it right. Does the setw function need to only be used with specific values?

Aucun commentaire:

Enregistrer un commentaire