Question 2
Back to Exercise
What is the output of the following C++ program?
#include <iomanip>
#include <iostream>
int main() {
std::cout << std::setfill('*') << std::setw(6) << 42 << '|'
<< std::left << std::setw(6) << 42 << '|'
<< std::setw(6) << "ab" << "|\n";
return 0;
}
- A ****42|42****|ab****| Correct
- B 42****|****42|****ab|
- C ****42|42****|****ab|
- D 42|42 |ab |
Correct Answer: Option A
The fill character and std::left are sticky; the width must be given again for every field. Right alignment is the default.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!