← Quiz: File Handling in C++: all 10 questions
Quiz: File Handling in C++ · Question 9 of 10
Why should you not save a struct containing a std::string with write()?
Why should you not save a struct containing a std::string with write()?
- A.write() only accepts int
- B.Strings are too long for a file
- C.The string holds a pointer to heap memory, so the file stores an address, not the characters
- D.It makes the file a text file
Answer & explanation
Correct answer: The string holds a pointer to heap memory, so the file stores an address, not the characters
Raw bytes of a pointer are meaningless when read back later; write the characters themselves.
Can you get the rest right without peeking?
Take the timed Quiz: File Handling in C++ quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →