LearnFrenzy
Sign in Take a free test

Input/Output with cin and cout · Predict the Output · Question 19

std::format with positional arguments and fill Answer, explanation & discussion

  • Output
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 19 Back to Exercise

What is the output of the following C++ program?

main.cpp
#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!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links