title: Why does getline() not read the last int value in the line?
body: <p>I have a file that contains a list of books. Each book has 4 variables delimitated by a Tab.</p>
  <p>The variables are</p>
  <ul>
  <li>Title</li>
  <li>author</li>
  <li>isbn</li>
  <li>qty</li>
  </ul>
  <p>and there are around 400 book entries.</p>
  <p>I have managed to write a function that reads each input to an array and saves it to a Book object.</p>
  <pre><code>void loadFile() {
    
      std::ifstream inputFile(&quot;books&quot;);
      std::string bookArray[4];
      std::string line;
      Book book;
      while (getline(inputFile, line)) {
          size_t field2 = 0;
          size_t field1 = line.find(&quot;\t&quot;);
          for (int i = 0; i &lt;= 3; i++) {
              size_t field1 = line.find(&quot;\t&quot; , field2);
              if (field1 != std::string::npos) {
                  std::string str2 = line.substr(field2, field1 - field2);
                  bookArray[i] = str2;
              }
              field2 = field1 + 1;
          }
          
          book.setTitle(bookArray[0]);
          book.setAuthor(bookArray[1]);
          book.setIsbn(bookArray[2]);
          book.setQty(stoi(bookArray[3]));
    std::cout &lt;&lt; &quot;Book:   &quot; &lt;&lt;book.getTitle &lt;&lt;'\t'&lt;&lt; book.getQty&lt;&lt; &quot; records.\n&quot;;
  }
  </code></pre>
  <p>but the function seems to not pick up the qty numbers at the end of each line. Everything else seems to be fine except the qty numbers. I cant find what's wrong with the function.</p>
  <p>I have tried implementing the same <code>getline()</code> function with a '\t' delimitator argument like so:</p>
  <pre><code>while(getline(input, line, '\t')) {
  </code></pre>
  <p>The output just read the title of the first line and stopped there. I know the first function works.<br />
  Why is it not picking up the <em>qty</em> values?</p>
  <p>The books file format is as follows:</p>
  <pre><code>A First Look at Graph Theory    Clark John; Holton Derek Allan  9788170234630   5
  A Practical Approach To Data Structures And Algorithms  Sanjay Pahuja   9788122420678   7
  A Practical Approach to High-Performance Computing  Sergei Kurgalin; Sergei Borzunov    9783030275587   6
  A Practical Guide to UNIX for Mac OS X Users    Mark G. Sobell; Peter Seebach   9780321629982   5
  A River Marc Martin 9781452162256   4
  </code></pre>
  <p>Total Noob here so I apologize if my code is awkward.</p>