🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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()?

  1. A.write() only accepts int
  2. B.Strings are too long for a file
  3. C.The string holds a pointer to heap memory, so the file stores an address, not the characters
  4. 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 →