Erase rows from file with condition IF

Hello,
i have an input txt file like this:

5,210000	
5,212508	
5,220000  //erase cause the next row has not the same second decimal number	
5,230000	
5,232030	
5,240000  //erase cause the next row has not the same second decimal number	
5,250000	
5,252057	
5,260000	
5,262869	
5,270000	
5,272579	
5,280000	
5,282832	
5,290000  //erase cause the next row has not the same second decimal number
5,300000		


My target is to eliminate the rows that not have the same second decimal number to the next row, instead if there are two lines consecutive with the same second decimal number i keep these. In the comment there are the rows that i want erase.
Dou you have some suggestions to do this?
Thank's in advance.
closed account (z05DSL3A)
You could read the file a line at a time into a vector of strings. iterate the vector and delete the lines that you don't want. Then write the lines out to a new file.
Since deletion is more or less anticipated, switching to a list would be a better choice than a vector. My 1 cent opinion :)
Or you could store an array of X characters for the previous line & read in the lines one by one, then only write them into the new file if the check against the previous line allows you to do so.
Aha another data structure proposed. It is always about algorithm and data structures in programming isn't it ? :P
erry121,
Do you use comma instead of dot in the capacity of decimal point in your input file? And is comments exists in your input file?
erry121,
Do you use comma instead of dot in the capacity of decimal point in your input file? And is comments exists in your input file?
Actually if I'm given such an assignment I would immediately implement it using Perl which will be quick and solve the requirement fast.

Of cuz if above is part of a big program then got no choice but to use C++.
Topic archived. No new replies allowed.