title: Creating a two-dimensional vector from a file?
body: <p>I'm trying to read data from a grid, in a 20x20 file. I'm using a two-dimensional vector of vectors of strings. </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;fstream&gt;
  #include &lt;vector&gt;
  
  using namespace std;
  
  #define HEIGHT 20
  #define WIDTH 20
  
  typedef vector&lt;vector&lt;string&gt; &gt; stringGrid;
  
  bool readGrid(stringGrid&amp; grid, string filename) {
  
      grid.resize(HEIGHT);
      for (int i = 0; i &lt; HEIGHT; i++)
          grid[i].resize(WIDTH);
  
      ifstream file;
      string line;
  
      file.open(filename.c_str());
  
      if (!file.is_open()) {
          return false;
      }
  
      for (int i = 0; i &lt; HEIGHT; i++)
      {
          while (getline(file, line)) {
              grid[i].push_back(line);
          }
      }
  
      return true;
  }
  
  void displayGrid(stringGrid grid)
  {
  
      for (int row = 0; row &lt; HEIGHT; row++)
      {
          for (int col = 0; col &lt; WIDTH; col++)
          {
              cout &lt;&lt; grid[col][row];
          }
          cout &lt;&lt; endl;
      }
  
  }
  
  
  int main(){
  
      stringGrid grid;
  
      readGrid(grid, "test.txt");
  
      displayGrid(grid);
  
      return 0;
  
  }
  </code></pre>
  
  <p>However, when I run this code, the program only outputs a few blank lines.
  Why doesn't this code work? The logic seems sound enough. </p>