I have a text file with 100 years of data (1900 - 2000). each year is having 365 or 366 entry depending on leap year or not. I want to store the data of each year in separate files. the data in the main file is like this,
dd mm yy data1
please help me to write a C++ program to short the data¬¬
If the data is small enough to fit in memory, read it into a container, sort it by year and for each year, create a file with a suitable name, write all records, close file.
@kbw
Yes I have all the fields in every line.
you are right!! it should be y. After changing it to y, it is giving the output for the year 1990 but when I am changing it to 1991/other (for the dataset of the year 1991/other years), it is not working!!!
@coder777
this is giving the output from 1990 - 2000, it is the same as in the main (data.wth) file.
but I want separate file for each year!!
At the moment, you have code that reads the file and writes all the 1990 data to the 1990 data file. So you need to think of a way of expanding that for all years.
You can't open a file for every year at the same time, you just have too many. So you can't open lots of files and use an if or switch statement to select which file you write to. You have to think of another way.
ya I understand that one!! but how can I short the data by year as you told. I think it is not possible by IF. please suggest how can modify the code!!!