* binary file parsing in C++
@ 2003-12-10 2:14 Justin Findlay
0 siblings, 0 replies; 4+ messages in thread
From: Justin Findlay @ 2003-12-10 2:14 UTC (permalink / raw)
To: gcc-help
Is there any way to read through a file bit by bit, instead of character
by character?
ifstream::read(), ifstream::readsome(), and ifstream::get() deal only in
chars (bytes).
Justin
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: binary file parsing in C++
2003-12-10 23:20 ` Justin Findlay
@ 2003-12-11 18:49 ` Segher Boessenkool
0 siblings, 0 replies; 4+ messages in thread
From: Segher Boessenkool @ 2003-12-11 18:49 UTC (permalink / raw)
To: Justin Findlay; +Cc: Eljay Love-Jensen, gcc-help
On 11-dec-03, at 0:20, Justin Findlay wrote:
> I am perplexed at what is happening here. This is a simple script that
> reads a file one byte at a time, and writes it to another file one
> byte at
> a time, but somehow there is an extra character at the end of the
> output
> file.
end-of-file only gets set after you try to read past the end of the
file,
not when you are _at_ the end of the file.
Segher
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: binary file parsing in C++
2003-12-10 13:10 ` Eljay Love-Jensen
@ 2003-12-10 23:20 ` Justin Findlay
2003-12-11 18:49 ` Segher Boessenkool
0 siblings, 1 reply; 4+ messages in thread
From: Justin Findlay @ 2003-12-10 23:20 UTC (permalink / raw)
To: Eljay Love-Jensen; +Cc: gcc-help
On Wed, 10 Dec 2003, Eljay Love-Jensen wrote:
>> Is there any way to read through a file bit by bit, instead of character by character?
>
> You'll have to write your own bit-by-bit reader.
>
> A class that HAS-A ifstream, and whose "get" method returns a bit (via bool or int or enum Bit { Zero, One }).
>
> Shouldn't be very hard.
I am perplexed at what is happening here. This is a simple script that
reads a file one byte at a time, and writes it to another file one byte at
a time, but somehow there is an extra character at the end of the output
file.
$ g++ --version
g++ (GCC) 3.3.2 20031022 (Red Hat Linux 3.3.2-1)
$ g++ binary.cpp
$ ./a.out
$ ls -ls
8 -rw-rw-r-- 1 justin justin 4258 Dec 9 20:11 bin
8 -rw-rw-r-- 1 justin justin 4259 Dec 10 16:14 bout
$ cat binary.cpp
//binary.cpp
#include <fstream>
using namespace std;
int main()
{
char b[ 1 ];
ifstream fin( "bin" );
ofstream fout( "bout" );
while ( fin.good() && ! fin.eof() )
{
fin.read( b, 1 );
fout.write( b, 1 );
}
return 0;
}
Justin
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: binary file parsing in C++
[not found] <Pine.LNX.4.44.0312091304350.18156-100000@bessie.cosmic.uta h.edu>
@ 2003-12-10 13:10 ` Eljay Love-Jensen
2003-12-10 23:20 ` Justin Findlay
0 siblings, 1 reply; 4+ messages in thread
From: Eljay Love-Jensen @ 2003-12-10 13:10 UTC (permalink / raw)
To: Justin Findlay, gcc-help
Hi Justin,
>Is there any way to read through a file bit by bit, instead of character by character?
You'll have to write your own bit-by-bit reader.
A class that HAS-A ifstream, and whose "get" method returns a bit (via bool or int or enum Bit { Zero, One }).
Shouldn't be very hard.
HTH,
--Eljay
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2003-12-11 18:49 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-12-10 2:14 binary file parsing in C++ Justin Findlay
[not found] <Pine.LNX.4.44.0312091304350.18156-100000@bessie.cosmic.uta h.edu>
2003-12-10 13:10 ` Eljay Love-Jensen
2003-12-10 23:20 ` Justin Findlay
2003-12-11 18:49 ` Segher Boessenkool
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).