title: C++ using g++, no result, no print
body: <p>I'm slowly moving from using Python to using C++ and I don't understand how to run any code. I'm using the g++ compiler, but I get no results from my functions.</p>
  
  <pre><code>// arrays example
  #include &lt;iostream&gt;
  using namespace std;
  
  int foo [] = {16, 2, 77, 40, 12071};
  int n, result=0;
  
  int main ()
  {
    for ( n=0 ; n&lt;5 ; ++n )
    {
      result += foo[n];
    }
    cout &lt;&lt; result;
    return 0;
  }
  </code></pre>
  
  <p>If I run this example inside VSCode and specify that I want to use g++ compiler it comes back with: <code>Terminal will be reused by tasks, press any key to close it.</code>. If I compile it through cmd and run the task, a new cmd window flashes and nothing is happening. </p>
  
  <p>I found the g++ doc which says how to compile with g++ and it shows the following example:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  void main (){
      printf("Hello World\n");
  }
  </code></pre>
  
  <p>But I can't even run the compiler because it says </p>
  
  <pre><code>error: '::main' must return 'int'
   void main(){
             ^
  </code></pre>
  
  <p>How can I print something in cmd or the ide terminal? I don't understand.</p>