getting a problem while using files
Jun 30, 2011 at 8:18pm UTC
when i put the following code the problem i am getting is that it displays the last bit of information, present in the file, twice other than that the code works perfectly.
what i mean is that if in the file the following information is there:-
book name book no
something 212
whatever 103
then the output is
212 something
103 whatever
103 whatever
1 2 3 4 5 6 7
ifstream ls("test.txt" );
while (ls)
{
ls.read((char *) &lib1,size);
cout<<"\n " <<lib1.bno<<" " <<lib1.bname;
}
ls.close();
can anyone please tell me what is wrong in the code...
Jun 30, 2011 at 8:27pm UTC
Try putting the call to read() inside the condition of the while loop.
Jul 1, 2011 at 12:54am UTC
you try with code:
ifstream ls("test.txt");
while(ls)
{
ls.read((char*) &lib1,size);
if(ls.eof()) break;
cout<<"\n "<<lib1.bno<<" "<<lib1.bname;
}
ls.close();
Jul 1, 2011 at 4:08am UTC
You try with code:
1 2 3 4 5 6 7 8
ifstream ls("test.txt" );
while (ls)
{
ls.read((char *) &lib1,size);
if (ls.eof()) break ;
cout<<"\n " <<lib1.bno<<" " <<lib1.bname;
}
ls.close();
Jul 1, 2011 at 5:32am UTC
thanks for the help it worked ..
Topic archived. No new replies allowed.