Clear the istream of error bits and seek back to the beginning of the file. Whether this is the optimal approach to what you want to do is another question depending on what your goal really is.
int main(int argc, char *argv[])
{
ifstream file("file.txt");
int n = count(istreambuf_iterator<char>(file), istreambuf_iterator<char>(), '\n') + 1;
file.clear();
file.seekg(0);
string row;
while (file >> row)
cout << row << endl;
return (0);
}