C++: Input pattern and find in text file



 DEVELOP > c-Plus-Plus > C++: Input pattern and find in text file

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "kittykat"
Date: 01 Dec 2004 11:53:06 AM
Object: C++: Input pattern and find in text file
Hi,
I was wondering if you could help me. I am writing a program in C++, and
the problem is, i have very limited experience in this language.
I would like my user to enter a specific pattern, and I want my program to
search a text file for this pattern, and let the user know if this pattern
exists or not.
So far, i have figured out how to make my prgram read the text file, but
i'm not sure how to take the information the user inserts and compare it
with the data in the text file.
It would be great if you could point me in the right direction, and give
me a few tips on how i should go about implementing this.
Thanx so much in advance.
.

User: "Dietmar Kuehl"

Title: Re: C++: Input pattern and find in text file 01 Dec 2004 12:32:09 PM
kittykat wrote:

I would like my user to enter a specific pattern, and I want my

program to

search a text file for this pattern, and let the user know if this

pattern

exists or not.

I assume your "pattern" is more complex than just a string which is
to be sought in the text file (otherwise the solution is trivially
to read the textfile into a 'std::string' or a 'std::vector<char>'
and use an appropriate 'find()' method or algorithm). That is, I
assume your pattern is more like a regular expression. In this case
your best option is probably to get the RegEx library from Boost
(<http://www.boost.org/>) and use it: a library similar to this will
be part of Library TR1 and is thus likely to become part of the next
revision of the C++ standard.
If you really want to program everything yourself, you should
investigate "finite state machines" and pattern matching: effectively,
you use a finite state machine to efficiently match a certain class
of patterns (essentially those which can't match nested parenthesis).
--
<mailto:dietmar_kuehl@yahoo.com> <http://www.dietmar-kuehl.de/>
<http://www.contendix.com> - Software Development & Consulting
.
User: "Richard Herring"

Title: Re: C++: Input pattern and find in text file 09 Dec 2004 10:32:13 AM
In message <1101925929.139614.314700@c13g2000cwb.googlegroups.com>,
Dietmar Kuehl <dietmar_kuehl@yahoo.com> writes

kittykat wrote:

I would like my user to enter a specific pattern, and I want my

program to

search a text file for this pattern, and let the user know if this

pattern

exists or not.


I assume your "pattern" is more complex than just a string which is
to be sought in the text file (otherwise the solution is trivially
to read the textfile into a 'std::string' or a 'std::vector<char>'
and use an appropriate 'find()' method or algorithm).

But even then, if the file is large the "appropriate" algorithm is
probably *not* one of the variants of std::find() or string::find(),
which are likely to be naive O(n*m) methods.
Google searching on "string search algorithm" will yield some useful
faster algorithms - Boyer-Moore, Knuth-Morris-Pratt, and no doubt many
others.
--
Richard Herring
.

User: "kittykat"

Title: Re: C++: Input pattern and find in text file 01 Dec 2004 12:40:11 PM
Thank you so much! I will look into that.
.



  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER