Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

std

iostream

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 ?

like image 994
Devos Avatar asked Mar 19 '23 09:03

Devos


1 Answers

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.

like image 150
Ivaylo Strandjev Avatar answered Mar 21 '23 23:03

Ivaylo Strandjev