Thread: reading in files

  1. #1
    Frustrated Programmer :( phantom's Avatar
    Join Date
    Sep 2001
    Posts
    163

    Question reading in files

    I know how to read in files and how to avoid spaces. But how do you only get the program to read in values that appear only AFTER a 'return' in a normal .txt file, i.e if the first value isn't right then ignore the rest of the line.

    james
    My site to register for all my other websites!
    'Clifton Bazaar'

  2. #2
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065

    Re: reading in files

    Originally posted by phantom
    I know how to read in files and how to avoid spaces. But how do you only get the program to read in values that appear only AFTER a 'return' in a normal .txt file, i.e if the first value isn't right then ignore the rest of the line.

    james
    Use some form of check to validate the data read in. Use "getline" to read in the entire line. Then check the first portion with strcmp to see if it matches your pre-defined value to ignore, if so, go on to the next line, if not, process the data in.

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    24
    You could also try something like this:

    #include <ctype.h>

    ifstream file;

    while (isalnum(file.peek()) {

    // Read in data ...
    // blah blah blah

    it uses the "is alapha numeric"

    good luck
    Skeptic

  4. #4
    Frustrated Programmer :( phantom's Avatar
    Join Date
    Sep 2001
    Posts
    163

    Cheers all

    Thanks for the responses, I'll get right onto it today
    My site to register for all my other websites!
    'Clifton Bazaar'

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading User Defined Files
    By Necrofear in forum C++ Programming
    Replies: 17
    Last Post: 06-30-2006, 12:55 AM
  2. Linking header files, Source files and main program(Accel. C++)
    By Daniel Primed in forum C++ Programming
    Replies: 3
    Last Post: 01-17-2006, 11:46 AM
  3. reading files
    By hiya in forum C++ Programming
    Replies: 7
    Last Post: 05-21-2005, 11:40 AM
  4. A little help reading from files...
    By Invincible in forum C++ Programming
    Replies: 4
    Last Post: 04-03-2002, 10:43 AM
  5. Need Advice in reading files
    By jon in forum C Programming
    Replies: 4
    Last Post: 10-07-2001, 07:27 AM