Question 18
Back to Exercise
What is the output of the following C++ program?
#include <iomanip>
#include <iostream>
#include <string>
int main() {
std::string s = "say \"hi\"";
std::cout << s << " | " << std::quoted(s) << " | " << std::quoted("a b", '\'') << '\n';
return 0;
}
- A say "hi" | "say \"hi\"" | 'a b' Correct
- B say "hi" | "say "hi"" | "a b"
- C say \"hi\" | "say \"hi\"" | 'a b'
- D say "hi" | say "hi" | a b
Correct Answer: Option A
std::quoted wraps the text in quotes and escapes quotes inside it with a backslash. The second argument chooses a different quote character.
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!