title: Reading from file which has text and numbers on same line into a array
body: <p>I have a file that has record of how many people picked specific color out of all people in different classrooms. I am trying to read that file into a array based on the color. for example if the color is Red I want to save the 2 numbers from that line into an array that keeps list of red numbers.The file is already formatted this way and cannot be changed.The first problem I encountered is that string is not read from file properly.</p>
  
  <p>Here is whats inside of the file. There were other colors as well I decided to only include them once the program runs properly</p>
  
  <pre><code>Red        18 20
  Black      15 20
  Red        13 18
  Black      12 16
  </code></pre>
  
  <p>Here is what I have tried</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  using namespace std;
  int main()
  {
      string myString = " ";
      int redArray[4]= {0};
      int blackArray[4] ={0};
      int counter = 0;
      std::ifstream myFile;
      myFile.open("record.txt");
  
      while (!myFile.eof())
      {
          getline(myFile, myString, ' ');     //Get the first text and ignore spaces
          //Runs this block if the color is red
          if (myString == "Red")
          {
              myFile &gt;&gt;redArray[counter];     //Get the numbers from the red rows
          }
          //Run this block if the color Black
          else if (myString == "Black")
          {
              myFile &gt;&gt;blackArray[counter];  //Get the number from black rows
          }
          counter++;
      }
      cout &lt;&lt;myString &lt;&lt;endl;    //to show if string is read properly
  
      //Display the values of redArray
      for (int i = 0; i &lt;4; i++)
      {
          cout &lt;&lt;redArray &lt;&lt;" ";           
      }
      cout &lt;&lt;endl;
      //Display the values of blackArrays
      for (int k = 0; k &lt;4; k++)
      {
          cout &lt;&lt;blackArray[k] &lt;&lt;" ";
      }
      return 0;
  }
  
  
  
  
  
  
  </code></pre>