Thread: Searching through a file

  1. #1
    Registered User
    Join Date
    Apr 2004
    Posts
    14

    Searching through a file

    Hi all,

    I'm wondering if anyone could help me find out how to search through a file. I know how to read a file, write to one etc, but am not sure how to find a specific word within a file and then return it.

    I've done a search but cannot seem to find anything

    Please could somebody help?

    Thanks a lot,
    Mike

  2. #2
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    it's sort of like searching an array of strings to find the one you want.


    declare an ifstream to read the file

    declare a string to acting as a holding variable

    declare a string to act as the target variable

    search the file using a loop

    each time through the loop read a new word into the holding variable and compare it to the target variable. If they are the same do something. If they are different do something different.

  3. #3
    Registered User
    Join Date
    Apr 2004
    Posts
    14
    Thanks for your reply

    What do you mean by holding and target variables? Are those just normal variables with different purposes?

    Thanks,
    Mike

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  2. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 03:44 PM
  3. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  4. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM