Article View: comp.sys.mac.programmer.codewarrior
Article #8getline() dilemna - text or binary?
From: Rick Ross
Date: Sun, 03 Sep 1995 18:01
Date: Sun, 03 Sep 1995 18:01
29 lines
2009 bytes
2009 bytes
I need to process text files one line at a lime. I'd like to use
istream::getline() to do it, but my input files come from many different
sources (Mac, DOS, and UNIX). Each of these uses a different convention
for representing the end of a line:
Mac - 0x0D (carriage return or '\r')
UNIX - 0x0A (linefeed or '\n')
DOS - 0x0D, 0x0A (carriage return/linefeed pair)
The istream::getline() member function allows the delimiter character to
be specified, but I can't specify more than one. Also, the "text" mode on
my compiler translates the DOS newline characters into a single '\n' for
input and expands it again on the way back out.
I'm wondering if anyone has come up with a convenient, efficient way to
read files a line at a time, regardless of the format of the text file? Is
there an easy way to make istream::getline() adaptive to the different
formats? Should I just open the file first, make a quick pass through a
few lines to determine which newline character is being used, and then use
that character as the delimiter?
========================================================================
Rick Ross - Iris Development Corporation - rick@iway.com
___ _ _ ___ makers of _____ _
| __|_ __ __ _(_) | | _ \_____ __ _____ _ _ |_ _|__ ___| |___
| _|| ' \/ _` | | | | _/ _ \ V V / -_) '_| | |/ _ \/ _ \ (_-<
|___|_|_|_\__,_|_|_| |_| \___/\_/\_/\___|_| |_|\___/\___/_/__/
Visit us on the World Wide Web at: "http://irisdev.com"
========================================================================
Technical Details
Message-ID:
<rick-0309951401280001@smurfy.irisdev.com>Path:
arc1-ca.pugleaf.net!smurfy.irisdev.com!userShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!smurfy.irisdev.com!user From: rick@iway.com (Rick Ross) Newsgroups: comp.sys.mac.programmer.codewarrior,comp.lang.c++ Subject: getline() dilemna - text or binary? Date: Sun, 03 Sep 1995 14:01:28 -0400 Organization: Iris Development Corp. Message-ID: <rick-0309951401280001@smurfy.irisdev.com> NNTP-Posting-Host: smurfy.irisdev.com X-Newsreader: Yet Another NewsWatcher 2.0b30