2uzhan.com
Advertisement
Now Place:2uzhan.com » File handling problem in C++

File handling problem in C++

C++ (Non Visual C++ Issues) @ April 6, 2006   Views:0

i am reading from text file, when all data fenishes in the file mean pointer reaches end of the file, tellg() return -1. that time i am calling seekg(0) for moving back to begining of the file. But pointer is not moving there and every time tellg() return -1.
how to solve this problem ?

--------------Solutions-------------

[ Moved Thread ]

The eofbit has been set when you reach the end of file.
So, try to call istream::clear() just before seeking to zero.

thanks that is the answer

char name[30];

while(!file.eof())
{
file>>name;
}

cout<<"E O F "<<name<<endl;

file.clear();

file.seekg (0, ios::beg);

file>>nam;

cout<<"First Entry "<<nam<<endl;

Tags:
© 2018 2uzhan.com Contact