title: reading strings and numbers from input file stream using getline
body: <p>I get the syntax for <code>getline(ifstream foo, string bar)</code> function and I know its third parameter which is delimiter, is set to '\n'.</p>
  
  <p>I have a file to read, and it has numbers on first and second column.
  The problem is that on the third column, I have to read names of countries which may have contain spaces.</p>
  
  <p>I've checked my code is successfully reading numbers from first two columns for sure, but as my code tries to read the country name , I get a <code>'Segmentation fault (cord dumped)'</code> error message.</p>
  
  <p>My code looks like this:</p>
  
  <pre><code>string name[50];
  double year1[50],year2[50];
  fstream ifstr;
  ifstr.open("thefile.csv");
  for (int i=0; (!(ifstr.eof())) || i &lt; 51; i++) {
  ifstr &gt;&gt; year1[i] &gt;&gt; year2[i];
  getline(ifstr, name[i]);} // expecting this line to be reading/storing
  //anything that comes after 3rd column into string array
  </code></pre>
  
  <p>The given variable for my assignment is way too long and complicated, so I kind of wrote that up to help readability, but that one line is pretty much the problem.</p>
  
  <p>From the instruction sheet, my professor mentioned </p>
  
  <blockquote>
    <p>Reading the populations is straightforward, and can be done using the
    standard file IO functions we covered in class (i.e., ">>" using an
    input stream). However, since the names of some countries contain
    spaces, we need to use getline instead of >> for the name field.
    Fortunately, the country is the final field so we can use ">>" to read
    the populations and then a getline to finish the line.
        You will need to input data until the end of file is reached. Recall that getline's return value is false if at end of file, so its
    easy to check for this.</p>
  </blockquote>
  
  <p>I looked up all sources available regarding this topic, but I couldn't find one that solves this so far.</p>
  
  <p>Please advise.</p>