title: How to search array of strings in C++
body: <p>I want to be able to search an array of strings in C++.  I have this data:</p>
  
  <pre><code>"Foo Becky, 924-334-2514", 
  "Becky Warren, 555-1223", 
  "Geri Palmer, 555-8787", 
  "Ron Palmer, 555-2783"
  </code></pre>
  
  <p>If the user types <code>Bec</code>, the program finds the name <code>Foo Becky, 924-234-2314</code>.  If the user types <code>Palmer</code>, then the program should show <code>Geri Palmer, 555-8787</code> and <code>Ron Palmer, 555-2783</code></p>
  
  <p>Here is what I have so far:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  using namespace std;
  int main(){
      int n;
      string search;
  
      while(1){
          cout &lt;&lt; "How many data you want to input: "&lt;&lt; endl;
          cin &gt;&gt; n;
          cin.ignore(1000, 10);
  
          if(n &gt; 0 &amp;&amp; n &lt; 20){
              break;
          }
          cout &lt;&lt; "Number of data can not be negative or more than 20. "&lt;&lt; endl;
      }
  
      string* data = new string[n];
  
      for(int i=0; i&lt; n; i++){
          cout &lt;&lt; "Enter [First Name] [Last Name], [Phone-Number] and then hit "
               &lt;&lt; "enter." &lt;&lt; endl &lt;&lt; "e.g: Foo Becky, 925-245-413"&lt;&lt; endl;
          getline(cin,data[i]);
          cout &lt;&lt; endl;
      }
  
      cout &lt;&lt; "Enter what you want to search for: "&lt;&lt; endl;
      getline(cin, search);
  
      for(int i =0; i&lt; n; i++){
          if(search == data[i]){
              cout &lt;&lt; data[i]&lt;&lt; endl;
          }
      }
      delete [] data;
      return 0;
  }
  </code></pre>
  
  <p>How do I search an array of strings in C++?</p>