Finding position in binary file using tellg()
CBSE12D-2016
Problem Statement - 04C
Find the output of the following C++ code considering that the binary file BOOK.DAT exists on the hard disk with a data of 200 books.
class BOOK { int BID;char BName[20]; public: void Enter();void Display(); }; void main() { fstream InFile; InFile.open("BOOK.DAT",ios::binary|ios::in); BOOK B; InFile.seekg(5*sizeof(B)); InFile.read((char*)&B, sizeof(B)); cout<<"Book Number:"<<InFile.tellg()/sizeof(B) + 1; InFile.seekg(0,ios::end); cout<<" of "<<InFile.tellg()/sizeof(B)<<endl; InFile.close(); }
Solution
CSKC| Created: 9-Jan-2019 | Updated: 14-Jan-2019|CBSE12D-2017