// created by Justin C. Miller
// created on 10-1-2001
// created for http://www.geocities.com/neonprimetime.geo/index.html
// BINARY INPUT/OUTPUT FILES
#include
#include // necessary for file input and output (ifstream, ofstream, fstream)
using namespace std ;
int main() {
int i ; // used in the for loops
int array[10] = { 45, 123, 123,12,1, 12,33, 65,23,12} ; // sample data
// CREATE A BINARY DATA FILE for OUTPUT
ofstream f_out ;
f_out.open("binData.dat", ios::out|ios::bin) ; // opening is for output (ios::out) and as a binary file (ios::bin)
// WRITING OUT MY SAMPLE DATA TO the FILE
for(i = 0 ; i < 10 ; i++)
f_out.write(reinterpret_cast (&array[i]), sizeof(array[i])) ;
f_out.close() ; // CLOSING THE OUTPUT FILE
int array2[10] ; // array to hold the data to be read in
// OPEN A BINARY DATA FILE for INPUT
ifstream f_in("binData.dat", ios::in|ios::bin) ; // opening for input (ios::in) and as a binary file (ios::binary)
// READING IN ALL THE DATA until i reach the end of the file
for(i = 0 ; !f_in.eof() && !f_in.fail() ; i++)
f_in.read(reinterpret_cast (&array2[i]), sizeof(array2[i])) ;
f_in.close() ; // closing the data file
// DISPLAYING MY INFO to the screen to PROVE it worked!
for(i=0 ; i<10 ;i++)
cout << array2[i] << " " ;
return 0 ;
}
               (
geocities.com/neonprimetime.geo/cpp)                   (
geocities.com/neonprimetime.geo)