title: Passing a command line argument input file to a class to parse
body: <p>There is probably a very simple solution to my problem but I am having some problems passing an input file (from command line arguments) into a class for parsing. </p>
  
  <p>Here is the relevant part of my main.cpp code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;chrono&gt;
  #include "SortingCompetition.h"
  
  int main(int argc, char** argv)
  {
      if (argc != 3)
      {
          std::cerr &lt;&lt; "Invalid arguments" &lt;&lt; std::endl;
          std::cerr &lt;&lt; "Usage: ./a.out &lt;input file&gt; &lt;output file&gt;" &lt;&lt; std::endl;
          return 1;
      }
  
      SortingCompetition sorter(argv[1]);
  
      return 0;
  }
  </code></pre>
  
  <p>Here is the SortingCompetition.h file:</p>
  
  <pre><code>#ifndef SORTINGCOMPETITION_H_
  #define SORTINGCOMPETITION_H_
  
  #include &lt;string&gt;
  #include &lt;vector&gt;
  using namespace std;
  
  class SortingCompetition{
  private:
      string&amp; input_;
      vector&lt;string&gt; data_;
  public:
      SortingCompetition(const string&amp; inputFileName);
      void setFileName(const string&amp; inputFileName);
      bool readData();
      bool prepareData();
      void sortData();
      void outputData(const string&amp; outputFileName);
  };
  
  #endif
  </code></pre>
  
  <p>All the functions must remain the same here. i.e. 
  <code>SortingCompetition(const string&amp; inputFileName);</code>
  must stay that way... I cannot remove the <code>const</code> or anything else.</p>
  
  <p>Here is the relevant implementation of SortingCompetition:</p>
  
  <pre><code>#include "SortingCompetition.h"
  
  SortingCompetition::SortingCompetition(const string&amp; inputFileName){
      input_ = inputFileName;
  }
  void SortingCompetition::setFileName(const string&amp; inputFileName){
      input_ =  inputFileName;
  }
  </code></pre>
  
  <p>This is where I'm getting problems, I'm not passing the input file from the command argument to the private variable correctly. I've searched for quite a while, but cannot find a solution.</p>