Hi I have a text File with a lot of data, which I am supposed to use as an input in a C++ program. There are several thousands observations and each observation is a line. The data is for a time period for a few years.
Now I have a code which reads all the data and makes calculations based on the all data.
NI have to make the same calculation but for shorter periods (e.g. instead of for the whole period I have to do calculations for every mounth to sum up all calculations and to find the mean and to see what is the deviation from the value for the whole period)
Now I have a problem with reading data form the text file for shorter periods... How can make the file suitbale for calculations for shorter periods? In the current version of the file I do not have any indications where a period is ending and a new one starting. How can I make the indications?
Regarding the code I was thinking to use fstream with getline().
// reading a text file
#include <iostream>
#include <fstream>
#include <string>
usingnamespace std;
int main () {
string line;
ifstream myfile ("textfile.txt"); //defines the lokation of the file
if (myfile.is_open())
{
while (! myfile.eof() ) // here is the indication until the end of the file, but I want to put it in earliar stage
{
//do the calculations
//save each calculation
}
myfile.close();
}
return 0;
}
In this context how can I indicate in the text file to which line the data should be readed? Or may be there is a better approach?