how can i achieve functionality like grep in c++

April 6, 2012 at 09:58:28
Specs: Windows 7
I want to look for a pattern in all the files inside a directory and then print the line number where the pattern matches.
the statement is: "Open the file and search for text. If there’s a match, display file name, line
number and the matching line."
I have to use standard libraries for this only.

See More: how can i achieve functionality like grep in c++

Report •

#1
April 6, 2012 at 10:30:36
If you don't want to use wildcards then just use string::find. But if you want to match regular expressions then you either need to do quite a lot of work yourself (http://linuxgazette.net/issue27/mueller.html) or use a non-standard library. But why restrict yourself to the regular libraries? Why not use one of the regular expression libraries that exist.

Unless this is a homework question (which I suspect may be the case) I can't understand the restriction that you can't use non-standard libraries in your program. If you link them statically the client doesn't need to have them installed. Good programmers don't re-invent the wheel.


Report •
Related Solutions


Ask Question