Question 14
Back to Exercise
What is the output of the following C++ program when the input is a b?
#include <iostream>
int main() {
char c1, c2, c3;
std::cin >> c1;
std::cin.get(c2);
std::cin >> c3;
std::cout << '[' << c1 << "][" << c2 << "][" << c3 << "]\n";
return 0;
}
- A [a][ ][b] Correct
- B [a][b][b]
- C [a][b][ ]
- D [a][ ][ ]
Correct Answer: Option A
get reads the space after a; >> then skips whitespace (none left before b) and reads b.
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!