1.

Suggest the situation where write() and read() are preferred over get() and put() for file I/O operations. Support your answer with examples

Answer»

The get() and put() functions perform I/O byte by byte. On the other hand, read() and write() functions let you read and write structures and objects in one go without creating need for I/O for individual constituent fields.

Example:

file.get(ch);

file.put(ch);

file.read((char *)&obj, sizeof(obj));

file.write((char *)&obj, sizeof(obj)); 



Discussion

No Comment Found

Related InterviewSolutions