title: piping input file from bash and read it line by line using getline(cin,line)
body: <p>I am trying to read the file using getline() function and <strong>piping my input file using bash command</strong> but get illogical output.</p>
  
  <p>This is my main.cpp code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;sstream&gt;
  #include &lt;string&gt;
  
  using namespace std;
  int main(int argc, const char * argv[]) {
  
      string line;
  
      while(getline(cin,line)){
          cout&lt;&lt;line&lt;&lt;endl;
      }
      return 0;
  }
  </code></pre>
  
  <p>My input file named input.txt look like this</p>
  
  <pre><code>4 MF MF FM FF MF MM
  MM FF
  MF MF MF MF FF
  </code></pre>
  
  <p>My bash command and running result</p>
  
  <pre><code>DENGs-MacBook-Pro:APS stevedeng$ g++ -o main main.cpp -std=c++11
  DENGs-MacBook-Pro:APS stevedeng$ ./main &lt; input.txt
  MF MF MF MF FFMF MM
  </code></pre>
  
  <p>What I thought is that the program will read the input.txt line by line and print the output exactly as the format as the input file. </p>
  
  <p>Can someone explain what is happening here with the only one line of wired looking output? </p>
  
  <p>How can I achieve the result of reading it line by line if the only way I can do is <strong>piping the input file from bash instead of using ifstream</strong>? Any help will be appreciated.</p>