Author: viro Language: cpp
Description: i give up Timestamp: 2008-03-19 14:34:40 -0400
View raw paste Reply
  1. #include <iostream>
  2. #include <string>
  3.  
  4.  
  5. using namespace std;
  6.  
  7.  
  8.  
  9. void setlist(string list);
  10. int main()
  11. {
  12.         int numOfNames =10;
  13.     string list[10];
  14.         string search;
  15.         string found;
  16.         int x=0;
  17.  
  18.         int i=0;
  19.  
  20.   //setlist
  21.  list[0] ="Becky Warren, 555--1223";
  22.  list[1] ="Joe Looney, 555-0097";
  23.  list[2] ="Geri Palmer, 555-8787";
  24.  list[3] ="Lynn Presnell, 555-1212";
  25.  list[4] ="Holly Gaddis, 555-8878";
  26.  list[5] ="Sam Wiggins, 555-0998";
  27.  list[6] ="Bob Kain, 555-8712";
  28.  list[7] ="Tim Haynes, 555-7676";
  29.  list[8] ="Warren Gaddis, 555-9037";
  30.  list[9] ="Jean James, 555-4939";
  31.  list[10]="Ron Palmer, 555-2783";
  32.  
  33.  
  34.  cout << "Please enter Name that you are looking for: ";
  35. getline(cin, search, '\n');
  36.  
  37.  
  38.  
  39.  
  40. for(i = list.find(search, 0); i != string::npos; i = list.find(search, i))
  41. {
  42.     found=list[x];
  43.        
  44.  
  45.         x++;
  46.        
  47.     i++;  // Move past the last discovered instance to avoid finding same
  48.           // string
  49. }
  50. cout <<found ;
  51.  
  52.  
  53.  
  54.  
  55. return 0;
  56. }
View raw paste Reply