Q:

c++ std::getline / std::sort is not working as expected

I have made a little program that loops line by line through file. Everything worked fine with UNIX line endings : 
 std::ifstream file(filename);
 while (std::getline(file, str))
 {
   std::sort(str.begin(), str.end());
   std::cout << str << ""; ----- WORKS as expected
 }

When using DOS line endings, the std::getline does not return a line. So more trial end error got me thinking, that I should, probably, delimit at " ". And that works:
std::ifstream file(filename);
while (std::getline(file, str, ' '))
{
  std::cout << str << ""; -- returns a line 
  std::sort(str.begin(), str.end());
  std::cout << str << ""; ----- does not work like the first time
}

The second try prints out a line normally but when inputing that line to sort it works unexpectedly. So my question is why is std::sort working differently at the second time? My first idea was that maybe variable type is different but that led to nowhere. What am I missing? Is it possible to get it working like in the first code block?

A:

Instead of 
std::cout << str << "";

you should try
std::cout << str << std::endl;

to get a new line in a proper way on all operating systems.

