![]() |
|
#1
|
|||
|
|||
Finding words in fileshi, my plan is to search for particular phrases within text based documents. I know how to read in the text file but afterwards this is where the questions begin. Should i be reading the file line by line or character by chAracter?
If i declare the string "here i am", is there a particular search or find function to look for this phrase within the text document? thanks, any help would be much appreciated! |
|
#2
|
|||
|
|||
Re: finding words in filesThe easiest way that I can think of is to load the entire text file into one string object, then look for a substring of that string that is equal to your phrase. This would be easy if you use the std::string object. Something like this:
CPP / C++ / C Code:
|
|
#3
|
|||
|
|||
Re: finding words in filesQuote:
You can do it any way that you want, single character, line by line or the entire file (assuming that the file isn't too large). Here's an example of searching through a file for a phrase: CPP / C++ / C Code:
Output: Code:
As you can see, I loaded the entire file into a dynamically allocated character buffer and then created a string from the buffer. This isn't very efficient, but makes the coding rather simple. This method requires "double" the memory of the file size, so it would be a dog with a relatively large file. :davis: |
|
#4
|
|||
|
|||
Re: finding words in filesthanks people, i found your posts very helpful
|
Recent GIDBlog
NARMY by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Named virtual host not working | Johnnyrotton | Apache Web Server Forum | 4 | 04-Sep-2007 20:32 |
| Undefined reference to pow | pisuke | C Programming Language | 6 | 02-Aug-2007 08:39 |
| Bloodshed Dev C++ Project Options | JdS | CPP / C++ Forum | 6 | 11-Nov-2005 17:23 |
| Checking source codes of image, audio and video files | onauc | C Programming Language | 5 | 26-Feb-2005 21:47 |
| Can't view pages from another machine on the Intranet | aevans | Apache Web Server Forum | 9 | 14-May-2004 02:26 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The