So I wanted to read 1000 lines from a huge file at a time, and I did the following:
while (true)
{
count := 0;
while (infile>> xyz && count <1000)
{
do something with xyz;
count ++;
}
do something;
if (count < 1000)
break;
}
}
The code runs smooth, however it takes a long time for me to find out some lines are missing from the output.
Eventually I found out it all occurs at
while (infile>> xyz && count <1000)
which means if count == 1000 it will still read another line to xyz but stops at the condition count<1000, and that line will never be processed.
Looks silly, but it does caused me a lot of panic.
No comments:
Post a Comment