Searching for words in text file

Hello everyone!

I am a 17yr old and I use TurboC++. I've made a airline ticket booking program as part of my first project. Now, what I've decided is that I'll put the flight schedule for all destinations in a .txt file. I'll get the desired destination from the user and then search for the specific flight details pertaining to that particular destination in the file. But I'm entirely clueless on how I can achieve this and need urgent help.

Suppose my file has the following text :

London-NewYork
4 Aug
06:10 : 23:30

London-Paris
4 Aug
05:30 : 07:30

Now, if the user says that he wants to go to Paris, I should be able to search my file for 'Paris' and display the above flight timings accordingly. How do I do this?


I'm not putting my already-2000-line code here as it is irrelevant to the problem I face.
Also, I'm kinda new to C++ (~1 year) and pretty much know only the basics thoroughly. So, if you're putting something in your code that you think might not be known to me, it'll be helpful to explain how it all works..

A quick response will be appreciated as I only have 5 more nights to stay up (and around 20 cups of coffee) to get over with this :)
loop through the file and search for "-Paris" (make sure the hyphon is there so you know it's a destination).
http://www.cplusplus.com/doc/tutorial/files/

Also keep a count of the line number.

When you find "-Paris", you'll know that two lines after this are your times.
Exactlyy, but how do I search for a string in the file? Do I check for the characters through a loop, or just compare the string altogether? For the second part again, how do I do that?
That link I posted shows how to get each line, then you can use various find methods of std::string:
http://www.cplusplus.com/reference/string/string/

like:
http://www.cplusplus.com/reference/string/string/find/
and
http://www.cplusplus.com/reference/string/string/substr/
Topic archived. No new replies allowed.