title: How to read int and strings from a text file?
body: <p>I have a text file containing name, ability, attack, and defense on every line, for instance:</p>
  
  <pre><code>Bill Punch 10 5
  Jack Jab 7 7
  Joe Kick 8 4
  </code></pre>
  
  <p>I would like to read the file and store its content. I could use an array, but I want to be able to continue to add rows. So I've implemented a function to count the lines. Arrays like to complain about values not being static at runtime so I moved to trying a vector. Below is the code.</p>
  
  <p>I'm attempting to insert every value into the x,y of the matrix, then go through and print it. But it's not working; it opens the command prompt and asks to input my file name. I do that, but then it just stops running.</p>
  
  <p>Also, how can I return the vector to my <code>main</code> function?</p>
  
  <pre><code>#include "stdafx.h"
  #include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  #include &lt;vector&gt;
  
  using namespace std;
  
  // Global Variables
  int numLines = 0;
  string fileName;
  int countLines();
  string openFile();
  
  int main() {
      string name, attack;
      cout &lt;&lt; "What is the name of your data file?" &lt;&lt; endl;
      getline(cin, fileName);
      cout &lt;&lt; countLines() &lt;&lt; endl;
      cout &lt;&lt; openFile() &lt;&lt; endl;
  }
  int countLines() {
      ifstream dataFile(fileName);
      string line;
      while (getline(dataFile, line)) {
          numLines++;
      }
      return numLines;
  }
  string openFile() {
      vector&lt;vector&lt;int&gt;&gt; dataVec(numLines, vector&lt;int&gt;(4));
      ifstream dataFile(fileName);
      string line;
      while (getline(dataFile, line)) {
          for (int i = 0; i == numLines - 1; i++) {
              for (int o = 0; o == 4; o++) {
                  cin &gt;&gt; dataVec[i][o];
              }
          }
      }
      while (getline(dataFile, line)) {
          for (int i = 0; i == numLines - 1; i++) {
              for (int o = 0; o == 4; o++) {
                  cout &lt;&lt; dataVec[i][o];
              }
          }
      }
      return dataVec;
  }
  </code></pre>