ifstream ReadFile

This is a discussion on ifstream ReadFile within the C# Programming forums, part of the General Programming Boards category; I am reading a file that is about 20 Mb, this will take about 10 seconds. A few lines from ...

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    383

    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 ?


    20080101,1
    20080102,2
    20080103,3
    20080104,4
    20080105,5
    20080106,6
    20080107,7


    Code:
    ifstream ReadFile("C:\\File1.txt");
    
    char Comma;
    std::string Date;
    double Number = 0;
    
    
    while( getline(ReadFile, Date, ',') )
    {
    
    	ReadFile >> Number;
    	ReadFile.get();
    
    	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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21