title: Pipe an input to C++ cin from Bash
body: <p>I'm trying to write a simple Bash script to compile my C++ code, in this case it's a very simple program that just reads input into a vector and then prints the content of the vector.</p>
  
  <p>C++ code:</p>
  
  <pre><code>    #include &lt;string&gt;
      #include &lt;iostream&gt;
      #include &lt;vector&gt;
  
      using namespace std;
  
      int main()
      {
           vector&lt;string&gt; v;
           string s;
  
          while (cin &gt;&gt; s)
          v.push_back(s);
  
          for (int i = 0; i != v.size(); ++i)
          cout &lt;&lt; v[i] &lt;&lt; endl;
      }
  </code></pre>
  
  <p>Bash script run.sh:</p>
  
  <pre><code>    #! /bin/bash
  
      g++ main.cpp &gt; output.txt
  </code></pre>
  
  <p>So that compiles my C++ code and creates a.out and output.txt (which is empty because there is no input). I tried a few variations using "input.txt &lt;" with no luck. I'm not sure how to pipe my input file (just short list of a few random words) to cin of my c++ program.</p>