Question 10
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
#include <iostream>
void report(std::ostream out) {
out << "ok\n";
}
int main() {
report(std::cout);
return 0;
}
- A report must return int
- B Streams cannot be copied (the copy constructor is deleted); pass the stream by reference: std::ostream& out Correct
- C cout cannot be passed to functions
- D ok needs std::endl
Correct Answer: Option B
Taking std::ostream& lets the same function write to std::cout, std::cerr, a file or a string stream.
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!