Ofstream does not print a new line for txt in Windows7

I have a problem when I want to print \nI use endlfor this. And the problem is that when I run the code on Windows7, it will not print a new line. But it will print a new line in Ubuntu. Both operating systems use the same GNU g ++ compiler.

So I am wondering if there is another way to print a new line for a file in Windows?

void translate(ofstream &out, const string &line, map<string, string> m)
{
   stringstream ss(line);
   string word;
   while(ss >> word)
   {
      if(m[word].size() == 0)
         out << "A";
      else
         out << m[word] << " ";
   }
   out << "\n";
}
+3
source share
1 answer

"\n", endl ( - endl flushes). \n , " ", . unix , \n . Windows \n \r\n ( , ). , , .

, , Windows, , , , . , cygwin g++ - g++-, Windows, . \n.

+3

Source: https://habr.com/ru/post/1784609/


All Articles