-
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;
}
}