Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CreateFile vs fopen vs ofsteam advantage & disadvantage?

Tags:

c++

c

CreateFile vs fopen vs ofsteam - advantage & disadvantage?

I heard that CreateFile powerful but only for windows.
Can you tell what should I use ( on windows) and why?

like image 272
Eveler Avatar asked May 28 '12 09:05

Eveler


1 Answers

It depends on what you're doing. For sequentially reading and writing text files, iostream is definitely the way to go. For anything involving transactional security or non-standard devices, you'll have to access the system directly (CreateFile or open). Even then, for sequential reading and writing of text, the best solution is to define your own streambuf, and use that with iostream.

I can't think of any context where fopen would be preferable.

like image 141
James Kanze Avatar answered Sep 29 '22 17:09

James Kanze