title: C++ fstream multiple input files
body: <p>I am writing a simple program to take in two files.  The terminal command line looks like this. </p>
  
  <pre><code>./fileIO foo.code foo.encode
  </code></pre>
  
  <p>When it runs, the second file is not read in.  When I enter </p>
  
  <pre><code>./fileIO foo.code foo.code
  </code></pre>
  
  <p>it works.  I can't seem to figure out why the second one is not opening.  Any ideas?  Thanks!</p>
  
  <pre><code>#include &lt;fstream&gt;
  #include &lt;iostream&gt;
  #include &lt;queue&gt;
  #include &lt;iomanip&gt;
  #include &lt;map&gt;
  #include &lt;string&gt;
  #include &lt;cassert&gt;
  using namespace std;
  
  int main( int argc, char *argv[] )
  {
    // convert the C-style command line parameter to a C++-style string,
    // so that we can do concatenation on it
    assert( argc == 3 );
    const string code = argv[1];
    const string encode = argv[2];
    string firstTextFile = code;
    string secondTextFile = encode;
  
    //manipulate the first infile
    ifstream firstFile( firstTextFile.c_str(), ios::in );
    if( !firstFile ) 
    {
      cerr &lt;&lt; "Cannot open text file for input" &lt;&lt; endl;
      return 1;
    }
  
    string lineIn;
    string codeSubstring;
    string hexSubstring;
    while( getline( firstFile, lineIn ) ) 
    {
      hexSubstring = lineIn.substr(0, 2);
      codeSubstring = lineIn.substr(4, lineIn.length() );
      cout &lt;&lt; hexSubstring &lt;&lt; ", " &lt;&lt; codeSubstring &lt;&lt; endl;
    }
  
    //manipulate the second infile
    ifstream secondFile( secondTextFile.c_str(), ios::in );
    if( !secondFile ) 
    {
      cerr &lt;&lt; "Cannot open text file for input" &lt;&lt; endl;
      return 1;
    }
  
    char characterIn;
    while( secondFile.get( characterIn ) )
    {
      cout &lt;&lt; characterIn &lt;&lt; endl;
    }
  
  
    return 0;
  }
  </code></pre>