while (!input.eof())
{
getline(input, line_input); // continues even ef getline(...) detects the eof
compare.open(argv[2]);
while (!compare.eof())
{
getline(compare, line_compare); // continues even ef getline(...) detects the eof
...
change to
1 2 3 4 5 6
while (getline(input, line_input)) // getline(...) returns [indirectly] true if anything is ok and false otherwise (eof)
{
compare.open(argv[2]);
while (getline(compare, line_compare))
{
...
I think coder777's algorithm will still output duplicate lines if they appear in the second file. How about this:
First loop: read the lines of txt1 into a set (a set provides faster lookup than a vector)
Second loop: read txt2 line by line. Try to find it in the set.
if you find it then {
output the line
remove the line from the set
}
Removing the line from the set will prevent duplicates from appearing.