Comparing values input to values in a vector
<p>I'm trying to input a form of data validation in which when a user enter's a book's ISBN number, if it has already been stored then it will output an error message. However, I'm having trouble doing this. I'm not sure if I'm overloading the == operator correctly, and I'm not sure how to compare the vector values in the store_ISBN() function.</p>

<p>Here is the code:</p>

<pre><code>#include "std_lib_facilities.h"

// Classes ---------------------------------------------------------------------

class Book{
public:
       vector&lt;Book&gt; books; // stores book information
       Book() {}; // constructor
       friend ostream&amp; operator&lt;&lt;(ostream&amp; out, const Book&amp; b);
       bool operator==(const Book&amp; d);
       string what_title();
       string what_author();
       int what_copyright();
       void store_ISBN();
       void is_checkout();
private:
        char check;
        int ISBNfirst, ISBNsecond, ISBNthird;
        char ISBNlast;
        string title;
        string author;
        int copyright;
};

// Class Functions -------------------------------------------------------------

string Book::what_title()
{
       cout &lt;&lt; "Title: ";
       getline(cin,title);
       cout &lt;&lt; endl;
       return title;
}

string Book::what_author()
{
       cout &lt;&lt; "Author: ";
       getline(cin,author);
       cout &lt;&lt; endl;
       return author;
}

int Book::what_copyright()
{
    cout &lt;&lt; "Copyright Year: ";
    cin &gt;&gt; copyright;
    cout &lt;&lt; endl;
    return copyright;
}

void Book::store_ISBN()
{
     bool test = false;
     cout &lt;&lt; "Enter ISBN number separated by spaces: ";
     while(!test){
     cin &gt;&gt; ISBNfirst &gt;&gt; ISBNsecond &gt;&gt; ISBNthird &gt;&gt; ISBNlast;
     for(int i = 0; i &lt; books.size(); ++i)
             if(ISBNfirst == books[i]) cout &lt;&lt; "test"; // no idea how to implement this line            
     if((ISBNfirst&lt;0 || ISBNfirst&gt;9) || (ISBNsecond&lt;0 || ISBNsecond&gt;9) || (ISBNthird&lt;0 || ISBNthird&gt;9))
                   error("Invalid entry.");
     else if(!isdigit(ISBNlast) &amp;&amp; !isalpha(ISBNlast))
          error("Invalid entry.");
     else test = true;}     
     cout &lt;&lt; endl;
}

void Book::is_checkout()
{
     bool test = false;
     cout &lt;&lt; "Checked out?(Y or N): ";
     while(!test){
     cin &gt;&gt; check;
     if(check == 'Y') test = true;
     else if(check == 'N') test = true;                                
     else error("Invalid value.");}
     cout &lt;&lt; endl;
}

// Operator Overloading --------------------------------------------------------

bool Book::operator==(const Book&amp; d){ // is this right???
     if((ISBNfirst == d.ISBNfirst) &amp;&amp; (ISBNsecond == d.ISBNsecond) 
             &amp;&amp; (ISBNthird == d.ISBNthird) &amp;&amp; (ISBNlast == d.ISBNlast)) return true;
     else return false;
}

ostream&amp; operator&lt;&lt;(ostream&amp; out, const Book&amp; b){
         out &lt;&lt; "Title: " &lt;&lt; b.title &lt;&lt; endl;
         out &lt;&lt; "Author: " &lt;&lt; b.author &lt;&lt; endl;
         out &lt;&lt; "ISBN: " &lt;&lt; b.ISBNfirst &lt;&lt; "-" &lt;&lt; b.ISBNsecond &lt;&lt; "-" &lt;&lt; b.ISBNthird &lt;&lt; "-" &lt;&lt; b.ISBNlast &lt;&lt; endl;
         out &lt;&lt; endl;
         return out;
}

// Main ------------------------------------------------------------------------     

int main()
{
    Book store;
    string question;
    while(true){
        store.what_title();
        store.what_author();
        store.what_copyright();
        store.store_ISBN();
        store.is_checkout();
        store.books.push_back(store);
        cout &lt;&lt; "Are you finished?(Y or N): ";
        cin &gt;&gt; question;
        if(question == "Y") break;
        else if(question == "N"){
              cout &lt;&lt; endl;
              cin.ignore();}
        else error("Invalid value.");
        }
    cout &lt;&lt; endl;
    cout &lt;&lt; "Books stored -\n" &lt;&lt; endl;
    for(int i = 0; i &lt; store.books.size(); ++i)
            cout &lt;&lt; store.books[i];
    keep_window_open();
}
</code></pre>

<p>Note that in the store_ISBN function I've only included testing for one variable since I don't want to type out the whole thing before I figure out how to do it.</p>

<p>As you can see each time a book passes through the loop in main, the data for that book is stored. I'm then able to output all the data input after the loop by overloading the &lt;&lt; operator to print Title, Author, and ISBN. So I think I should be able to access that individual data in the vector to compare to the user input ISBN, but I don't know how. The parts that I am confused about have been commented as such.</p>
