Devos
Devos

Reputation: 142

std::stream write / read vs operator << / operator >>

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 ?

Upvotes: 4

Views: 2082

Answers (1)

Ivaylo Strandjev
Ivaylo Strandjev

Reputation: 70931

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.

Upvotes: 7

Related Questions