title: Passing text file instead of user input as command line argument
body: <p>I'm trying to figure out how to be able to read in a .txt file as a command prompt argument instead user input.  If I have the program </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "cmdline.h"
  using namespace std;
  
  int main (int cnt, char * args[]) {
      int a = cmdline_int(args, 1);
      int b = cmdline_int(args, 2);
      cout &lt;&lt; "sum = " &lt;&lt; a &lt;&lt; " + " &lt;&lt; b &lt;&lt; " = " &lt;&lt; a + b &lt;&lt; endl;
      return 0;   
  }
  </code></pre>
  
  <p>where the file "cmdline.h" contains</p>
  
  <pre><code>#include &lt;cstdlib&gt;
  #include &lt;string&gt;
  using namespace std;
  
  int cmdline_int( char* cmdline_a[], int n ) {
    return atoi( cmdline_a[ n ] );
  }
  char cmdline_char( char* cmdline_a[], int n ) {
    char c = cmdline_a[ n ][0];
    return c;
  }
  </code></pre>
  
  <p>I can run the program as </p>
  
  <blockquote>
    <p>./program 3 5</p>
  </blockquote>
  
  <p>and the output will be </p>
  
  <blockquote>
    <p>sum = 3 + 5 = 8</p>
  </blockquote>
  
  <p>however if I have a file (textfile.txt) that simply contains those same numbers in list form, i.e.</p>
  
  <pre><code>3
  5
  </code></pre>
  
  <p>and try to run it as </p>
  
  <blockquote>
    <p>./program &lt; textfile.txt</p>
  </blockquote>
  
  <p>I get </p>
  
  <blockquote>
    <p>Segmentation fault</p>
  </blockquote>
  
  <p>it does the same thing if textfile.txt contains "3 5", though its important that I use a text file in list form anyway.  What do I need to change to make "./program textfile.txt" have the same output as "./program 3 5" ?<br>
  I'm guessing the problem lies between the int main parenthesis, I'm just not sure what specifically.  </p>