search word in file

Reply

Join Date: Dec 2007
Posts: 3
Reputation: Tell Me is an unknown quantity at this point 
Solved Threads: 0
Tell Me Tell Me is offline Offline
Newbie Poster

search word in file

 
0
  #1
Dec 6th, 2007
Hi,

I want to ask if there function in library of c++ to search word in file ??

thank you
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 1,670
Reputation: vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold 
Solved Threads: 192
vmanes's Avatar
vmanes vmanes is offline Offline
Posting Virtuoso

Re: search word in file

 
0
  #2
Dec 6th, 2007
Not that I know of. You have to read some (all) of the file, then search using any of several possible methods.

If you expand on your problem definition, and show the work you've done to solve it, you will get better help here.

Please read the forum rules.

Val
"We Americans got so tired of being thought of as dumb by the rest of the world that we went to the polls last November and removed all doubt."
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,541
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 704
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: search word in file

 
0
  #3
Dec 6th, 2007
>I want to ask if there function in library of c++ to search word in file ??
No. You need to break it down into smaller operations like reading a file and searching a string for a word. Then you can do this:
  1. std::ifstream in ( "myfile" );
  2.  
  3. if ( in ) {
  4. bool found = false;
  5. std::string search_for = "teapot";
  6. std::string word;
  7.  
  8. while ( in>> word ) {
  9. if ( word == search_word ) {
  10. found = true;
  11. break;
  12. }
  13. }
  14.  
  15. //...
  16. }
Or this:
  1. std::ifstream in ( "myfile" );
  2.  
  3. if ( in ) {
  4. bool found = false;
  5. std::string search_for = "teapot";
  6. std::string line;
  7.  
  8. while ( std::getline ( in, line ) ) {
  9. if ( word.find ( search_word ) != std::string::npos ) {
  10. found = true;
  11. break;
  12. }
  13. }
  14.  
  15. //...
  16. }
For example.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 3
Reputation: Tell Me is an unknown quantity at this point 
Solved Threads: 0
Tell Me Tell Me is offline Offline
Newbie Poster

Re: search word in file

 
0
  #4
Dec 7th, 2007
thank you
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC