How to read utf-8 text file line by line?

I want to read some utf-8 text files line by line in c++ using std::codecvt_utf8 facet and getline function, on a windows machine. My program works fine for some files but is failed for some others. For those failed ones, my program can read only one single line, but they can be loaded in Sublime successfully with correct number of lines.

I have tried the method mentioned in another stackoverflow answer . The code is as following:

std::wifstream wif(filename);
wif.imbue(std::locale(std::locale::empty(), new std::codecvt_utf8<wchar_t>));
std::wstringstream wss;
wss << wif.rdbuf();

std::wstring wstr;
int num = 0;
while (std::getline(wss, wstr))
{
  num++;
}
std::cout << "Number of lines: " << num << std::endl;

Runnning the above code on this text file . I expected the output to be 3, but the actual output is 1.

PS: the question is marked as duplicated with (Read file line by line using ifstream in C++) . However the answers there won't work for this case.