Mail Archives: djgpp/1998/09/15/17:15:24
From: | "Jonadab the Unsightly One" <jonadab AT zerospam DOT com>
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | [gcc] fstream and non-textual data: EOF problem.
|
Date: | 15 Sep 1998 20:50:34 GMT
|
Organization: | Belly Laugh Software
|
Lines: | 55
|
Message-ID: | <01bde0ea$cdbb1180$LocalHost@jonadab>
|
NNTP-Posting-Host: | craw-cas1-cs-3.dial.bright.net
|
Mime-Version: | 1.0
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Thanks to all who helped me get gcc installed correctly.
Now I have a new problem.
Apparently, reading in a byte with int istream::get()
will not read past the first occurance of decimal 26,
as it considers that to mean EOF regardless of
the length of the file. That wouldn't be a problem
reading in text, but I'm trying to read in a non-text
format, byte-for-byte, and I need to be able to read
the whole file. Should I be using something other
than fstream, or is there something simple I am
missing to tell the stream to allow binary data?
Here's my source code. The for loop was originally
a do loop, checking for eof condition, but that
terminated the loop as soon as 26 was read in,
so I tried what follows. Now every byte starting
with the first 26 is reported as -1.
int main ()
{
ifstream *infile;
infile = new ifstream; infile->open("infile2.txt");
int value;
int counter;
int filelen;
cout << "Length of file (in bytes)? ";
cin >> filelen;
for (counter=1; counter<=filelen; counter++)
{
value = infile->get();
cout << value << endl;
}
// Now, clean up.
infile->close();
return 0;
}
--
All my usenet posts are General Public License.
Dyslexic email address: ten DOT thgirb AT badanoj
- Raw text -