title: Using getline() to read input (with spaces) from file into a structure
body: <p>I am currently in a C++ data structures class and I am extremely new to c++. My goal here is to read lines from a file and store them into a structure.  The lines contain elements of a book. My problem is that some lines have spaces, and I'm not sure how to properly read them into a structure. I can't seem to use <code>getline()</code> correctly to read the lines into each element of the structure. If I run it as is, I get the message <code>error: expected primary expression before 'infile'</code>.  Apologies if this post isn't formatted correctly, this is also my first stack overflow post! Any help??</p>
  
  <p>This is what my structure looks like:</p>
  
  <pre><code>typedef struct book {
      char title[100];
      char author[100];
      char publisher[100];
      float price;
      char isbn[100];
      int pages;
      int copies;
  } Book;
  </code></pre>
  
  <p>And this is how I am trying to read lines into the structure:</p>
  
  <pre><code>for (int i=0; i &lt; currentIndex; i++) {
      getline(ifstream infile, my_book[i].title);
      getline(ifstream infile, my_book[i].author);
      getline(ifstream infile, my_book[i].publisher);
      getline(ifstream infile, my_book[i].price);
      getline(ifstream infile, my_book[i].isbn);
      getline(ifstream infile, my_book[i].pages);
      getline(ifstream infile, my_book[i].copies);
      currentIndex++;
  }
  </code></pre>
  
  <p>The text file will have book information listed as such:</p>
  
  <pre><code>Magician: Apprentice
  Raymond E. Feist
  Spectra (January 1, 1994)
  5.02
  0553564943
  512
  1
  </code></pre>