while(!fis.eof())
{
lines2++;
fis >> str;
}
two problemss:
1) that counts the number of words, not lines. If you really want lines then call getline()
2) That will count the last line/word twice because eof() doesn't work lilke that. Here's how to code the loop
while( fis >> str)
++lines2;