Thread: Need help with reading in files.

  1. #16
    Super Moderater.
    Join Date
    Jan 2005
    Posts
    374
    Several meg files is nothing nowdays to read into memory at once


    Ok so maybe you can, however, if you could do the same with just reading one line into the buffer surely this would be better?

    Recall the OP said:-

    There is 939197 lines in this file.
    Are you saying he should read all those lines into memory?

    I'm just saying if you could make the code more efficient then surely that would be the optimal choice? Right?

  2. #17
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    Quote Originally Posted by treenef
    Are you saying he should read all those lines into memory?

    I'm just saying if you could make the code more efficient then surely that would be the optimal choice? Right?
    Yes -- that's only about 70 meg (or less, assuming each line is 80 or fewer characters) file which can easily fit in most computers today.

    The only reason I mentioned reading the whole file at once was because of the requirement to determine the offset from the beginning of the file to the start of the search string found. Reading one line at a time in text mode on MS-Windows operating system can lead to erroneous file offsets. It would be easier, and probably faster too, to do that in memory.

  3. #18
    Super Moderater.
    Join Date
    Jan 2005
    Posts
    374
    The only reason I mentioned reading the whole file at once was because of the requirement to determine the offset from the beginning of the file to the start of the search string found.
    Yes the OP was a bit vague with his description of this. Personally, if the program said this word was found in line whatever, that would be satisfactory for most people.

    Why he would want to determine the offset from the beginning of the file is a little confusing. Moreover, by this does he mean how many words into the file it is, or how many chars - or what?

    Anyway, I guess that's for the OP to decide.


  4. #19
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    To convert an istream into a boolean, the compiler calls a member function called istream:: operator void*().
    Good Lord, I'm soooo happy that I may program in C++ like a real man, where boolean checks are performed on void pointers. Not like those Java pussies who'd probably call operator bool() to find out if something is true or false
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

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