title: How to ask, programmatically, a compiler to compile a file in C++?
body: <p>The following is my C++ program:</p>
  
  <p><i>main.cpp</i> </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  
  using namespace std;
  
  int main() {
  
      ofstream fileWriter;
      fileWriter.open ("firstFile.cpp");
      fileWriter &lt;&lt; "#include &lt;iostream&gt;" &lt;&lt; endl;
      fileWriter &lt;&lt; "int main() {" &lt;&lt; endl;
      fileWriter &lt;&lt; "\tstd::cout &lt;&lt; \"hello world\" &lt;&lt; std::endl;" &lt;&lt; endl;
      fileWriter &lt;&lt; "\treturn 0;" &lt;&lt; endl;
      fileWriter &lt;&lt; "}" &lt;&lt; endl;
      fileWriter.close();
  
      return 0;
  }
  </code></pre>
  
  <p>When the above program is executed, it creates a text-file named "firstFile.cpp" containing the following code:</p>
  
  <p><i>firstFile.cpp</i></p>
  
  <pre><code>#include &lt;iostream&gt;
  int main() {
      std::cout &lt;&lt; "hello world" &lt;&lt; std::endl;
      return 0;
  }
  </code></pre>
  
  <p>which, when executed, prints "hello world" on the screen.</p>
  
  <p>So, I would like to add to the <i>main.cpp</i> file lines of code asking GCC to compile the new <i>firstFile.cpp</i> just created.</p>
  
  <p>I am using GNU gcc on both platform Ubuntu and Windows.</p>
  
  <p>Is it possible to get any error code form the call to the compiler? If not why.</p>