Question 14
Back to Exercise
What is the output of the following C++ program on a 64-bit system?
#include <map>
#include <print>
#include <string>
#include <vector>
int main() {
std::vector<int> v{1, 2, 3};
std::map<std::string, int> m{{"b", 2}, {"a", 1}};
std::println("{}", v);
std::println("{}", m);
std::println("{:>5}|{:<5}|", "x", 3.5);
std::print("no newline ");
std::println("then one");
return 0;
}
- A [1, 2, 3] {"a": 1, "b": 2} x|3.5 | no newline then one Correct
- B 1 2 3 a 1 b 2 x|3.5 | no newline then one
- C [1, 2, 3] {"b": 2, "a": 1} x | 3.5| no newline then one
- D Compilation error
Correct Answer: Option A
C++23 can format ranges directly: vectors print as [..] and maps as {key: value} (strings quoted). println adds a newline, print does not.
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!