title: Declaring a vector of pointers to vector of strings
body: <p>I have a 2D table of strings (using STL vector) and am trying to modify so that the table is a vector of pointers to vectors of strings. I know that this will require changing the constructor so that rows are created dynamically, and pointers to the rows are inserted into the table, but I'm not sure how to go about creating this table in the first place.</p>
  
  <p>In my .h file:</p>
  
  <pre><code>class StringTable
  {
  public:
  
      StringTable(ifstream &amp; infile);
  
      // 'rows' returns the number of rows
      int rows() const;
  
      // operator [] returns row at index 'i';
      const vector&lt;string&gt; &amp; operator[](int i) const;
  
  private:
      vector&lt;vector&lt;string&gt; &gt;  table;
  
  };
  </code></pre>
  
  <p>In my .cpp file:</p>
  
  <pre><code>StringTable::StringTable(ifstream &amp; infile)
  {
      string          s;
      vector&lt;string&gt;  row;
  
      while (readMultiWord(s, infile))  // not end of file
      {
          row.clear();
          do
          {
              row.push_back(s);
          }
          while (readMultiWord(s, infile));
          table.push_back(row);
      }
  }
  
  int StringTable::rows() const
  {
      return table.size();
  }
  
  const vector&lt;string&gt; &amp; StringTable::operator[](int i) const
  {
      return table[i];
  }
  </code></pre>
  
  <p>I feel like this is probably a pretty easy switch, but I don't have a lot of experience using vectors, and I'm not sure where to start. Any guidance is greatly appreciated!</p>