Advertisement

Sponsors




Go Back   Zune Boards > Help Forum > Tech. help

New Member?



 
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Tech. help Come here for help with technology related problems.

Closed Thread
 
LinkBack Thread Tools
Old 12-02-2008, 10:09 AM   #1 (permalink)
Expert Zuner
 
ChurchedAtheist's Avatar
 
Join Date: Nov 2006
Posts: 3,495
Reputation: 455
Default c++

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.
__________________

Quote:
Originally Posted by Marcus Aurelius
Live a good life. If there are gods and they are just, then they will not care how devout you have been, but will welcome you based on the virtues you have lived by. If there are gods, but unjust, then you should not want to worship them. If there are no gods, then you will be gone, but will have lived a noble life that will live on in the memories of your loved ones.




ChurchedAtheist is offline  

Advertisement [Remove Advertisement]
Old 12-02-2008, 10:18 AM   #2 (permalink)
Resident Huge Arab
Retired Staff
Zune Priest
 
Locke's Avatar
 
Join Date: May 2008
Location: Invicta, Planet Bob
Posts: 6,800
Reputation: 1142
Send a message via MSN to Locke Send a message via Skype™ to Locke
Awards Showcase
Biggest Abuser of Noobs 
Total Awards: 1
Default

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....
__________________




Locke is online now  
Old 12-02-2008, 10:47 AM   #3 (permalink)
Expert Zuner
 
ChurchedAtheist's Avatar
 
Join Date: Nov 2006
Posts: 3,495
Reputation: 455
Default

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");

}
__________________

Quote:
Originally Posted by Marcus Aurelius
Live a good life. If there are gods and they are just, then they will not care how devout you have been, but will welcome you based on the virtues you have lived by. If there are gods, but unjust, then you should not want to worship them. If there are no gods, then you will be gone, but will have lived a noble life that will live on in the memories of your loved ones.

Last edited by ChurchedAtheist; 12-02-2008 at 10:59 AM..




ChurchedAtheist is offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump


All times are GMT -8. The time now is 05:15 PM.

 
Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.2.0 RC8
vB Ad Management by =RedTyger=
(C) ZuneBoards 2006-2007
Copyright © 2006 - 2008 Zune Boards | About Zune Boards | Legal | A member of the Crowdgather Forum Community