Alex Rivera | Logout

Which C I/O library should be used in C++ code?

Asked 2008-09-23T04:14:47.157
35

In new C++ code, I tend to use the C++ iostream library instead of the C stdio library.

I've noticed some programmers seem to stick to stdio, insisting that it's more portable.

Is this really the case? What is better to use?

Edit
Report

2 Answers

4

For binary IO, I tend to use stdio's fread and fwrite. For formatted stuff I'll usually use IO Stream although as Mikael said, non-trival (non-default?) formatting can be a PITA.

answered 2008-09-23T04:56:40.067
1

stdio is better for reading binary files (like freading blocks into a vector<unsigned char> and using .resize() etc.). See the read_rest function in file.hh in http://nuwen.net/libnuwen.html for an example.

C++ streams can choke on lots of bytes when reading binary files causing a false eof.

answered 2008-09-23T06:01:51.410

Your Answer