Hello.
I have two files. I want to compare them line by line:
first line of first file with first line of second file,
second line of first file with second line of second file,
...etc.
How can I read file by line in C++? I've found fgets, but it's C command, not C++.
Now I want to check (before comparison) that file1 and file2 have equal number of lines. This can count the lines:
1 2 3 4 5 6 7 8
int c = 0;
string str;
fstream file3("file2.txt");
while(!file3.eof())
{
getline(file3,str);
c++;
}
The problem is that I have to write "file3" to make it work in main() function above. Otherwise, it won't compare file2 with file1. How can I combine this two pieces of code without "file3" ?
I still have one "theoretical" question.
To work with files we can use FILE * (an object containing information to control a stream)
or fstream (an input/output file stream class).
In what situations we should choose one or another?
Yeah pretty much, but I like my traditional scanf and printf better than fstream. I think there should be a method supporting that syntax rather than the verbose and weird << syntax.