title: std::vector subscript out of range while reading a file into the vector of strings in C++
body: <p>I am new to c++. I am learning fast, but i dont know much yet.</p>
  
  <p>I cannot see the problem with index in this function:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  #include &lt;vector&gt;
  
  using namespace std;
  
  void get_rows(string filepath, vector&lt;string&gt; &amp;rows);
  
  int main() {
       vector&lt;string&gt; rows;
       get_rows("ninja.txt", rows);
  
       for (int i = 0; i &lt; rows.size(); i++) {
            cout &lt;&lt; rows[i] &lt;&lt; endl;
       }
  }
  
  void get_rows(string filepath, vector&lt;string&gt; &amp;rows) {
  
       ifstream file;
       file.open(filepath);
  
       string str;
       int index = 0;
  
       while (!file.eof()) {
  
             getline(file, str);
             rows[index] = str;
             index++;
       }
  }
  </code></pre>
  
  <p>Any help will be appreciated.</p>