title: printing system command to text file c++
body: <p>I have the following code, but when I run it, the output is printed instead of being copied to the text file.</p>
  
  <pre><code>void checkText()
  {
      ifstream my_file("test.txt");
      if (my_file.good()) {
          cout &lt;&lt; "File exist" ;
      }
      else {
          ofstream outputFile;
          outputFile.open("test.txt");
          outputFile &lt;&lt; system("head -n 1024 words.txt");
          outputFile.close();
          cout &lt;&lt; "Done!\n";
      }
  }
  </code></pre>
  
  <p>How do I print the system command to my text file?</p>