Question 19
Back to Exercise
What is the output of the following C++ program?
#include <format>
#include <iostream>
int main() {
std::cout << std::format("{1}-{0}-{1}", "a", "b") << ' '
<< std::format("{:*^9}", "mid") << ' '
<< std::format("{:#06x}", 26) << '\n';
return 0;
}
- A b-a-b ***mid*** 0x001a Correct
- B a-b-a ***mid*** 0x1a
- C b-a-b mid****** 0x001a
- D b-a-b ***mid*** 00001a
Correct Answer: Option A
{1} and {0} pick arguments by index and may repeat. *^9 centres in 9 characters padded with *. #06x adds 0x and zero-pads the whole field to 6 characters.
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!