title: How to send input to c++ through python
body: <p>I have used the following code to pass input to cpp program which reads input and prints it. </p>
  
  <pre><code>from subprocess import Popen, PIPE
  
  p = Popen(['a.exe'], shell=True, stdout=PIPE, stdin=PIPE)
  for ii in range(10):
      value = str(ii) + '\n'
      value = bytes(value, 'UTF-8')  # Needed in Python 3.
      p.stdin.write(value)
      #p.stdin.flush()
      result = p.stdout.readline().strip()
      print(result)
  </code></pre>
  
  <p>Following was the output of python</p>
  
  <pre><code>b''
  b''
  b''
  b''
  b''
  b''
  b''
  b''
  b''
  b''
  </code></pre>
  
  <p>EDIT:
  Following is the code for cpp file</p>
  
  <pre><code>#include&lt;iostream&gt;
  using namespace std;
  
  int main()
  {
      int a[10];
      for(int i=0;i&lt;10;i++)
      {
          cin&gt;&gt;a[i];
          cout&lt;&lt;a[i];
          std::cout.flush();
      }
      return 0;
  }
  </code></pre>