title: getchar() and even system("pause") do not stop program from closing
body: <p>I put file to cin stream via command argument like this:</p>
  
  <pre><code>./program &lt; input.txt
  </code></pre>
  
  <p>And I have this simple code:</p>
  
  <pre><code>std::vector&lt;std::string&gt; getLines(std::istream&amp; input)
  {
      std::vector&lt;std::string&gt; data;
      std::string line;
      int i = 0;
      char c;
      while (input.get(c))
      {
          if (c == '\n')
          {
              data.push_back(line);
              i = 0;
          }
          else
              line += c;
      }
      return data;
  }
  
  int main(void)
  {
      double elapsed;
      std::vector&lt;std::string&gt; out;
  
      Timer timer_1;
      // the data is now in cin stream so I pass it to function above
      out = getLines(std::cin);
      elapsed = timer_1.elapsed();
  
      for (unsigned int i = 0; i &lt; out.size(); i++)
          std::cout &lt;&lt; out[i] &lt;&lt; '\n';
      std::cout &lt;&lt; elapsed &lt;&lt; '\n';
  
      // now try to stop program from closing:
      std::getchar();    // doesn't work
      system("pause");   // doesn't work either
  
      // this doesn't work too
      while (getchar() != '\n');
      getchar();
  
      // program exits before I can see the output
      return 0;
  }
  </code></pre>
  
  <p>Of course I could just breakpoint the last statement but this cannot be done in release.
  If you are interested in Timer class I took it from <a href="https://stackoverflow.com/a/19800231/10732434">this answer</a>.</p>