title: Searching Vector of Structs for String C++
body: <p>I am attempting to compare a string against a struct element in a vector of structs. I have created the vector correctly, but cannot seem to get the if statement to work. It always returns true. What is the proper way to do this?
  
  Struct:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>struct customer{
      string name;
      string phoneNumber;
      string addressLine1;
      string addressLine2;
  };
  </code></pre>
  
  <p>Loop to iterate over vector containing if statement:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>cout&lt;&lt;"Input customer's phone number: ", cin&gt;&gt;phoneNumber, cout&lt;&lt;endl;
  int foundIndex = 0;
  bool found = false;
  for(int it = 1; it &lt; customers.size(); it++){
      if(phoneNumber.compare(customers[it].phoneNumber)){
          cout&lt;&lt;"Found at "&lt;&lt;foundIndex&lt;&lt;endl;
          cout&lt;&lt;"Name: "&lt;&lt;customers[foundIndex].name&lt;&lt;endl;
          cout&lt;&lt;"Phone Number: "&lt;&lt;customers[foundIndex].phoneNumber&lt;&lt;endl;
          cout&lt;&lt;"Address: "&lt;&lt;customers[foundIndex].addressLine1&lt;&lt;endl&lt;&lt;"                 "&lt;&lt;customers[foundIndex].addressLine2&lt;&lt;endl;
          found = true;
          break;
      }
  }
  </code></pre>
  
  <p>Function to populate Vector from CSV:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>vector&lt;customer&gt; readFile(void){
      string name;
      string phoneNumber;
      string addressLine1;
      string addressLine2;
      vector&lt;customer&gt; customers;
      vector&lt;string&gt; temper;
      customer temp;
      fstream ioFile;
      ioFile.open("customers.csv", fstream::in | fstream::out | fstream::app);
      while (!ioFile.eof()){
          getline(ioFile, name);
          temper = split(name);
          temp.name = temper[0];
          temp.phoneNumber = temper[1];
          temp.addressLine1 = temper[2];
          temp.addressLine2 = temper[3];
          customers.push_back(temp);
      }
  
      ioFile.close();
      return customers;
  }
  </code></pre>