Is there a way in Windows to read lines from a file, given a file handle? The file has to be opened with CreateFile
because of locking and specifying certain flags, so I have a file handle. My first attempt was to read in character by character with ReadFile
until I encounter the CRLF
sequence, but this is painstakingly slow, so I'm looking for an existing buffered solution before I write my own buffered file class.
Asked
Active
Viewed 227 times
0

Felix Dombek
- 13,664
- 17
- 79
- 131
-
Hmm, if you use MSVC++ then you have enough in the C runtime library to avoid having to drop down to CreateFile(). What "locking and certain flags"? – Hans Passant Apr 25 '15 at 17:03
-
Winapi method are generally low level. I really doubt that something exists if the API that does the buffering for `CRLF` delimited lines. Maybe it could exist in Windows Foundation Classes but never tried myself – Serge Ballesta Apr 25 '15 at 17:05
-
@HansPassant specifically `FILE_SHARE_READ` (but not write/delete) and `FILE_FLAG_SEQUENTIAL_SCAN` (in fact the creationDisposition, shareMode and flags/attributes are part of a public API I cannot easily change, but I guess I could dig around and see how to emulate this behaviour using C runtime functions...) – Felix Dombek Apr 25 '15 at 17:10
-
1can [this SO question](http://stackoverflow.com/questions/475853/can-i-use-createfile-but-force-the-handle-into-a-stdofstream) help ? – Christophe Apr 25 '15 at 17:14