4

For std::stream / ostream / istream / ...: What is the difference between using operators << and >> or using write() and read() methods ?

I suppose for binary writing/reading you should use write/read, but Is there any difference for text/ASCII ?

1 Answer 1

7

write and read do not understand anything about the data being printed - for them all there is are bytes. << and >> on the other hand understand what you print and can be overloaded only for a given datatype. As a consequence read and write are generally faster - no complex logic happens, we simply print bytes to the stream.

Sign up to request clarification or add additional context in comments.

2 Comments

... Also, this does not touch on the text / binary file divide, which is handled at a lower layer.
read and write themselves are certainly faster, but because they deal in unformatted data, we have to add formatting functions to insert data into and extract it out of the buffer. (Admittedly, formatting binary data is typically faster than formatting text, but you still can't ignore it completely.)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.