Article View: alt.comp.lang.learn.c-c++
Article #579Re: Reading Binary or Hex Data from a File
From: Ronald Steedman
Date: Fri, 04 Feb 2000 00:00
Date: Fri, 04 Feb 2000 00:00
21 lines
1787 bytes
1787 bytes
ifstream will do what you want. You just have to set it to "binary mode".
// open file in binary mode
ifstream fin;
fin.open("file.dat", ios::in | ios::binary);
// read raw data into buffer
char* buffer = new char[256];
while ( fin.read(buffer, 256) ) {
// process buffer
}
-- Ron Steedman
Alex Sramek <losal4@mminternet.com> wrote:
: Hi, I have a bunch of .dat files that I need to read with a program I'm
: making. However, I haven't found a way, with my limited c++ experience, to
: do so. If fstream is used, special characters will most likely be
: overlooked, and the data I'm reading has a range from 00 to FF. I'd like to
: read it in hex, or as 8-bit integers, or even bitwise... I just want to read
: it and make sure everything gets in OK.
Technical Details
Message-ID:
<87dtf2$10b$1@news.fsu.edu>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<s9knkid5dh169@corp.supernews.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 109fba,34922ce457bf482
X-Google-Attributes: gid109fba,public
X-Google-Thread: 1118e6,34922ce457bf482
X-Google-Attributes: gid1118e6,public
X-Google-Thread: 103c8d,34922ce457bf482
X-Google-Attributes: gid103c8d,public
X-Google-Thread: 114592,34922ce457bf482
X-Google-Attributes: gid114592,public
From: Ronald Steedman <steedman@quake.cs.fsu.edu>
Subject: Re: Reading Binary or Hex Data from a File
Date: 2000/02/04
Message-ID: <87dtf2$10b$1@news.fsu.edu>
X-Deja-AN: 581421125
References: <s9knkid5dh169@corp.supernews.com>
X-Complaints-To: abuse@fsu.edu
X-Trace: news.fsu.edu 949647650 1035 128.186.121.151 (4 Feb 2000 07:00:50 GMT)
Organization: FSU Computer Science Department
User-Agent: tin/pre-1.4-19990517 ("Psychonaut") (UNIX) (Linux/2.2.13 (i686))
NNTP-Posting-Date: 4 Feb 2000 07:00:50 GMT
Newsgroups: alt.comp.lang.learn.c-c++,borland.public.cppbuilder.language,borland.public.cppbuilder.vcl,comp.lang.c++