Question 6
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
#include <fstream>
int main() {
std::ofstream out("data.bin", std::ios::binary);
int values[3] = {1, 2, 3};
out.write(values, sizeof values);
return 0;
}
- A sizeof cannot be used on arrays
- B write() takes const char*; convert explicitly with reinterpret_cast<const char*>(values) Correct
- C binary mode is not allowed with write
- D values must be a vector
Correct Answer: Option B
The cast makes the "raw bytes" intent visible.
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!