Re: string comparision in a file
From: Thomas Matthews (Thomas_MatthewsSpitsOnSpamBots_at_sbcglobal.net)
Date: 07/21/04
- Next message: Connell Gauld: "Visual C++ 6 Compilation Problem"
- Previous message: Omid Rouhani: "Re: Redirect COUT to file"
- In reply to: rakesh: "string comparision in a file"
- Next in thread: David Rubin: "Re: string comparision in a file"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 21 Jul 2004 18:33:46 GMT
rakesh wrote:
> Hi,
> I have a requirement in which I need to search a string in a file
> stored on a harddisk. String which needs to be searched would be
> stored in a file with delimiter as new line character. some of the
> ways of doing this are
>
> 1. Read each line and do string compare immediately.
> 2. Read each line, add each string into a stl vector and search for
> the given string using stl bineary_search algorithm.
>
> It would be helpful if someone could give me comparison of which would
> be the best method among the above mentioned ways of handling
> searching. I would also welcome any other better of handling searching
> string in a file.
>
> Thanks,
> Rakesh.
If your system supports muli-tasking (multi-threading or whatever),
you could have one task reading lines into a buffer while another
task searches a given line.
This would assume that reading a line takes longer than searching it
and there is considerable overhead time when reading a line (such as
hard-drive start-up time, seeking time, etc.). Although these
timings usually only appear when the number of lines to read in
is huge; or the I/O overhead times are really slow.
Hmmm, why do things simple when you can have some fun making them
more complex? ;-)
--
Thomas Matthews
C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book
- Next message: Connell Gauld: "Visual C++ 6 Compilation Problem"
- Previous message: Omid Rouhani: "Re: Redirect COUT to file"
- In reply to: rakesh: "string comparision in a file"
- Next in thread: David Rubin: "Re: string comparision in a file"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|