Thread: file reading

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    2

    file reading

    To great C++ programmer.
    If i want to read source file and write its contents to destination file. However, The program must check certain sentence first. This line can be anywhere in the file. It must have "tel" and "=".
    Like this
    File A
    Tel = area code + number // Must check whether this line exist
    703-461-****
    703-461-**%%
    What i am thinking is using getline()
    //////////////////////////////////////////////////////////
    string buffer;
    while(getline(infile,buffer))//check line by line
    //////////////////////////////////////////////////////////

    How can i let the program check the sentence first?

  2. #2
    Unregistered
    Guest
    Probably best to read every line into program one by one and search for the substring "Tel =" using one of several techniques depending what type of string you are using. Once you have found the desired substring you can do what you want--write next two lines to destination file, stop writing to destination file, display "Mary Had A Little Lamb" on the screen, whatever.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. opening empty file causes access violation
    By trevordunstan in forum C Programming
    Replies: 10
    Last Post: 10-21-2008, 11:19 PM
  2. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 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. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM