Is it possible..?

Hey guys,

Is it possible to search a text file for a line that begins with certain characters and then be able to display the whole line?

For example, searching for a line starting with "lookThisUp:" in file containing:

Find: thisString
Next: NextString
lookThisUp: This should be printed
Last: LastString

and so the output would be "lookThisUp: This should be printed".

Thanks in advance
Yes, its known as Parsing... Here is an example that helped me a while back :

http://bytes.com/topic/c/insights/652951-how-parse-file-c
In a while(getline( my_input_file, my_string )) { loop, check if my_string.compare(0, test_string.length(), test_string) == 0 and cout << my_string; in that case.
It'll be a bit more ugly if you want to use char arrays.
See the reference on this site if you have any questions about the functions used
man grep
I wouldn't go to the trouble of grep-ing for a literal match. I'd do pretty much what hamsterman sketched out.

When I'm esp. lazy, I use if(0 == my_string.find("what I'm looking for")) to find things at the beginning of a string.
Thanks guys, very helpful :)
Topic archived. No new replies allowed.