Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It looks like you pretty much have all the code you need already! I copied your code and compiled it with some changes to read the SalesPeople in from a file in a loop. I will include the changes below, but since this is for your homework, you may just want to read and think about the following hints before looking at the code.</p> <ul> <li><p>For reading the SalesPeople in a loop, I would recommend that you take a look at this <a href="http://www.parashift.com/c++-faq-lite/input-output.html#faq-15.2" rel="nofollow noreferrer">FAQ</a>. It has an example of almost exactly what you need. <a href="http://www.parashift.com/c++-faq-lite/input-output.html#faq-15.4" rel="nofollow noreferrer">FAQ 15.4</a> will also help you, I believe.</p></li> <li><p>For your question on how to handle the extra empty line when reading from the file, check out this <a href="http://www.cplusplus.com/reference/iostream/manipulators/ws/" rel="nofollow noreferrer">link</a>. You can very simply extract whitespace this way.</p></li> <li><p>As jfclavette suggested, I would recommend looking into <a href="http://www.cplusplus.com/reference/string/getline/" rel="nofollow noreferrer">std::getline</a> for reading in the SalesPerson's full name, since you need everything on that line into one string.</p></li> </ul> <p>I have one question for you, though: what about the employeeID? I notice that it is being ignored in your sample code. Is that on purpose?</p> <p>And now, if you still need help, you can check out the code I wrote to get this to work:</p> <pre><code>istream &amp;operator&gt;&gt;(istream &amp;stream, SalesPeople &amp;salesppl) { //stream &gt;&gt; salesppl.fullname; getline(stream, salesppl.fullname); stream &gt;&gt; salesppl.startYear; stream &gt;&gt; salesppl.status; // not sure how to read that empty extra line here ? stream &gt;&gt; ws; return stream; } while(read &gt;&gt; employee) { // cout &lt;&lt; employee; // to verify the input, uncomment this line employees.push_back(employee); } </code></pre> <p>Also, as jfclavette suggested, it may not be a bad idea to add some input validation (check the stream status after reading from it and verify that it is still good). Although I would recommend using the while() loop for the reasons stated in <a href="http://www.parashift.com/c++-faq-lite/input-output.html#faq-15.5" rel="nofollow noreferrer">FAQ 15.5</a>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload