85.1k views
0 votes
What is the output of the following statements?

cout << setfill('*');
cout << "12345678901234567890" << endl;

cout << setw(5) << "18" << setw(7) << "Happy" << setw(8) << "Sleepy" << endl;

1 Answer

4 votes

Final Answer:

The output of the following statements is: 1234567890123456789018HappySleepy*.

Explanation:

The code snippet uses the setfill and setw manipulators to format the output. The setfill manipulator sets the fill character to *. The setw manipulator sets the width of the next output field to the specified value. The first output statement prints the string “12345678901234567890” followed by a newline character.

The second output statement prints the integer 18 with a width of 5, followed by the string “Happy” with a width of 7, and finally the string “Sleepy” with a width of 8. Since the width of the output fields is greater than the width of the values being printed, the remaining space is filled with the fill character, which is *. Therefore, the output of the code snippet is: 1234567890123456789018HappySleepy*.

User Vanlightly
by
8.6k points