Re: reading a binary file

From: Stephen Markacs (stephen@cuphy3.phys.columbia.edu)
Date: Thu Apr 15 1999 - 20:35:39 MEST


> {
>   ifstream f;
>   int bufferSize = 10;
>   int* buffer = new int(bufferSize);
                         ^          ^
These parenthesis should be brackets [].
As you have it, bufferSize is used to initialize the single integer that
buffer points to rather than specifying how big the buffer is.


> 
>   f.open("testdata/test.dat",ios::binary);
> 
>   f.read( (char*)buffer, bufferSize*sizeof(int));
> 
>   for (int i=0;i<bufferSize;i++)
>     cout << *(buffer++) << endl;
> }


   S t e p h e n   M a r k a c s
   stephen@phys.columbia.edu
   http://phys.columbia.edu/~stephen/ 



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:43:31 MET