title: Pipe to my program as a log rotator
body: <p>I'm trying to implement my own log rotator (create new log file whenever filesize reaches 10 MB). The part that reads the standard input and writes it to the file is this:</p>
  
  <pre><code>fstream file("log.txt", ios::out | ios::app);
  while (std::cin &gt;&gt; lineInput) {
      file &lt;&lt; lineInput;
  }
  </code></pre>
  
  <p>But the problem is that piped data gets ruined. Tabs and new lines are always lost. So for example if my program's name is <code>LogRotator</code>, then the command:</p>
  
  <pre><code>ls | ./LogRotator
  </code></pre>
  
  <p>Just concatenates all the file names together, like this:</p>
  
  <pre><code>LogRotatormain.oMakefile
  </code></pre>
  
  <p>while the output of <code>ls</code> is:</p>
  
  <pre><code>LogRotator main.o Makefile
  </code></pre>
  
  <p><strong>My question:</strong> How can I make the standard streaming preserve everything, including tabs, newlines, etc.?</p>