reading a binary file

From: Marcelo Munhoz (munhoz@physics.wayne.edu)
Date: Thu Apr 15 1999 - 19:59:01 MEST


	Hello All,

	I'm trying to read a binary file using an ifstream object, and
retrieving the data using a pointer. Unfortunately, it does not work in ROOT
(segmentation violation), although it works in plain C++. The macro I'm using
is:

{
  ifstream f;
  int bufferSize = 10;
  int* buffer = new int(bufferSize);

  f.open("testdata/test.dat",ios::binary);

  f.read( (char*)buffer, bufferSize*sizeof(int));

  for (int i=0;i<bufferSize;i++)
    cout << *(buffer++) << endl;
}

	If I change the pointer buffer by an array buffer[10], it works. But, I
want to set the array size dinamically, that's why I used a pointer.

	I'm running my macro in a Sun machine.

	Thanks for any comment or help.

		Marcelo


-- 
Marcelo G. Munhoz
Universidade de Sao Paulo - Brazil 
or
Wayne State University
666 West Hancock
Detroit - MI   48201
phone: (313)5775419
       



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