You didn't answer this question from my previous post:
abstractionanon wrote: |
---|
Is the data always in timestamp order on the disk? |
Line 8 is not going to work the you are thinking it does. rdbuf() returns a pointer to a streambuf. The << operator using a streambuf pointer will:
Retrieve as many characters as possible from the input sequence controlled by the stream buffer object pointed by sb (if any) and inserts them into the stream, until either the input sequence is exhausted or the function fails to insert into the stream.
http://www.cplusplus.com/reference/ostream/ostream/operator%3C%3C/
This does NOT mean that the << operator will read the entire file. Only that it transfer as many characters as the streambuf holds.
I see no reason to read the entire file into a stringstream. That is what your ifstream is for. The ifstream will continue to return data until the entire file has been read doing physical reads from the disk as needed.
q139 wrote: |
---|
Can getline read line from stringstream to string |
Yes, however, your line 11 is bogus. There are two variants of getline.
1) istream::getline which reads into a character array and returns an istream reference.
http://www.cplusplus.com/reference/istream/istream/getline/
2) getline (string) which reads from an istream into a string and also returns an istream reference.
Neither returns a string. What you want is this:
1 2
|
getline (buffer, currentline);
|
Since the file consists of variable length text records, there is no easy way to position into the file by line number. Since it does not appear that you have line number is the record on disk, the bisecting search approach I outlined above won't work. Now if you were to change the file format to a fixed record size, that would somewhat simplify the bisecting search I outlined by eliminating the need to scan for the start of the next record.
I would not worry about the time it takes to read 100,000 records. That's less than a 3MB file given the ~26 byte record format you've shown above.
I would simply read records from the file as follows:
1 2 3 4 5 6 7 8 9 10
|
string date, time;
double data;
while (getline(myfile,currentline))
{ stringstream ss(currentline); // Convert line to stringstream
ss >> date >> time >> data;
if (filter(date, time))
{ // Create datapoint on graph
}
}
|