Hi All,
Can any body tell me how to fix the errors in this program? I am reading integer values from a binary file and displaying them!
errors that I have:
error C2040: 'pBinaryFile' : 'class std::basic_ifst ream<char,struc t std::char_trait s<char> >' differs in levels of indirection from 'struct _iobuf *'
error C2228: left of '.tellg' must have class/struct/union type
error C2065: 'file' : undeclared identifier
error C2228: left of '.seekg' must have class/struct/union type
Can any body tell me how to fix the errors in this program? I am reading integer values from a binary file and displaying them!
Code:
int i;
ifstream::pos_type size;
ifstream pBinaryFile ("binaryfile.bin", ios::in|ios::binary|ios::ate); //other format to read from the binary file
if (!pBinaryFile)
{
printf("Unable to open file!");
return 1;
}
size = pBinaryFile.tellg(); //to get the size of the binary file in bytes
file.seekg (0, ios::beg); // and then go to the beginning of the file to read from it
for ( counter=1; counter <= (size/sizeof(int)); counter++)
// divided over sizeof because I want to read as long as the number of int values
{
fread(&i,sizeof(i),1,pBinaryFile);
printf("%d ",i);
}
cout<<endl;
fclose(pBinaryFile);
error C2040: 'pBinaryFile' : 'class std::basic_ifst ream<char,struc t std::char_trait s<char> >' differs in levels of indirection from 'struct _iobuf *'
error C2228: left of '.tellg' must have class/struct/union type
error C2065: 'file' : undeclared identifier
error C2228: left of '.seekg' must have class/struct/union type
Comment