Thread: ifstream ReadFile

  1. #1
    Registered User
    Join Date
    Dec 2007

    ifstream ReadFile

    I am reading a file that is about 20 Mb, this will take about 10 seconds.
    A few lines from this file look like below. The first value is a date value that go from lower to higher and the second value after the "Comma" is a number.
    In the while statement that do read this file from top to bottom there is a if-statement that says: if( Date == "20080103" )

    Now is my question this Let us say that I am only interested to read the lines that are inbetween the Date 20080103 - 20080106
    This will meen that I will only read the nescessary lines from this 20 Mb file.
    So is it possible to search for an entry and an exitpoint in this file instead of reading the file from top to bottom ?
    Is it possible to "search" for the date and know what line in the file that date is and do a startpoint from this line ?


    ifstream ReadFile("C:\\File1.txt");
    char Comma;
    std::string Date;
    double Number = 0;
    while( getline(ReadFile, Date, ',') )
    	ReadFile >> Number;
    	if( Date == "20080103" )
    		int i = 5;
    Last edited by Coding; 05-14-2008 at 03:34 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. ifstream
    By Wraithan in forum Tech Board
    Replies: 3
    Last Post: 09-24-2006, 01:26 AM
  2. ReadFile function fails.
    By dpkeller in forum C++ Programming
    Replies: 2
    Last Post: 12-03-2004, 09:20 PM
  3. Opening file using ifstream...[Urgent]
    By alvifarooq in forum C++ Programming
    Replies: 2
    Last Post: 09-26-2004, 10:42 AM
  4. ofstream and ifstream for searching and writing
    By johnnyd in forum C++ Programming
    Replies: 6
    Last Post: 03-17-2003, 07:34 AM
  5. Using API function ReadFile()
    By Echidna in forum Windows Programming
    Replies: 4
    Last Post: 10-23-2001, 10:33 PM
Website Security Test