I have this code but every time I run it,it only prints 11(the number of words in the array) over and over again when the amount of words is over 10. When the amount of words is under 10, nothing prints. Please help
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
string word;
fstream file;
int count = 1;
file.open("file.txt");
int numOfLines=0;
while(!file.eof())
{
getline(file,word);
numOfLines++;
}
if(numOfLines<10)
{
while(!file.eof())
{
getline(file,word);
cout << word << endl;
count++;
}
cout << "The entire file has been displayed";
}
else
{
for(int i=0; i<10;i++)
{
cout << word << endl;
}
}
}