Help - Search - Members - Calendar
Full Version: Search Text File For A Word Using C++
BleepingComputer.com > Software > Programming
   
ardynne
Hi, I am trying to write a c++ code that searches a text file for a word. If you are familiar with VB, this is what I am after:

Open textFile For Input As #1
i1=1
Do

Line Input #1, dataline
dataline = lcase$(dataline)
i1 = InStr(1, dataline, "word")
If i1 = 0 Then i1 = 1

Loop Until Mid(dataline, i1, 4) = "word" Or EOF(1)

i.e.: Open file for input (read), and search each line for the word
Thanks a lot for your help guys,
A
groovicus
Here is code for reading a file into an array of lines:
http://www.differentpla.net/node/117

Then all one needs to do is search the given line for the string. Java has a method called 'contains', I am guessing that c++ probably has the same thing.
ardynne
Thanks for the help, although I have to admit that it will take me a while to get my mind around this, specially when having to deal with pointers and other such C++ delicatessen! but never the less I'll try.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.