|
  
|
|
|
#1 (permalink) |
|
n00blet chef
Jr. Staff
Expert Zuner |
ok, this is programing help, but afaik we don't have a programing section
I am stuck on a particular function of a program I am working on. "void searchRecords() This void function should prompt the user for search text, then open C:\PhoneBook.txt for input, read all records in the file, and display all lines that contain the search text. Display a count of the records that matched the search text. Display a different message if zero, one, or more matches are found." an example line in phonebook.txt would be allen 407566432 any ideas? I know I need to use string.find function to do it, just not sure how.
__________________
![]() |
|
|
|
|
#2 (permalink) |
|
Official Editor of the SB
Support Team
Moderator Zune Lord |
You can always stuff it here: http://www.zuneboards.com/forums/dev...scussions-172/
![]() Gimme a sec here, I think I have something like it somewhere....
__________________
![]() |
|
|
|
|
#3 (permalink) |
|
n00blet chef
Jr. Staff
Expert Zuner |
does this look right?
void searchrecords() { ifstream indata; string rec, line1; int match; cout << "Please enter the item to search for: "; cin >> rec; indata.open("phonebook.txt"); while (!indata.eof()) { getline(indata, line1); if (line1.find(rec) != string ::npos) { match++; cout << line1 << endl; } } if(match == 0) cout << "0 matches found." << endl; if(match == 1) cout << "1 match found." << endl; if(match >= 1) cout << match << " matches found." << endl; indata.close("phonebook.txt"); }
__________________
Last edited by EndUnknown : 12-02-2008 at 11:59 AM. ![]() |
|
|
![]() |
| Thread Tools | |
|
|
| |