Perhaps a set would be useful? As you read a line, try to put the line into a set. http://www.cplusplus.com/reference/set/set/
It probably won't preserve the order that you see the lines. Would that be a problem?
actually a set would work nicely if we directly output each line to output file after determining that it does not exist in the set and was added to set.
Thank to both of you SIK and booradley60, it seems like using sets may solve my problem, sorry if it was too obvious from the beginning, but I didn't knew about the existence of sets.