Hello student0312,
PLEASE ALWAYS USE CODE TAGS (the <> formatting button), to the right of this box, when posting code.
Along with the proper indenting it makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/
Hint: You can edit your post, highlight your code and press the <> formatting button. This will not automatically indent your code. That part is up to you.
You can use the preview button at the bottom to see how it looks.
I found the second link to be the most help.
|
Any reason you are opening a text file as binary?
If you are going to use "std::string" and "std::getline" you need the header file "<string>". "string.h" is a C header file and not the same as the C++ "string".
Also "stdio.h" and "string.h" should be "cstdio" and "cstring" to use the proper C++ version of the C header files. Also you should not need either for a C++ program.
while (!file1.eof())
does not work the way that you are think of. You are doing the read after you check for "eof", so "c1", (and "c2"), will end up 1 larger than it should be.
A thought here, instead of reading the file every time you need something consider reading the file into a vector or an array. This way you can use the array instead of reading the files each time you need something.
When I did get the program to run I found that you are reading each line of the file and comparing the two strings. This is not what you want. The idea would be to read line 1 of "file1" and compare it to each line of "file2". This is where the vector or array would work better. Also the number of lines in each file would not have to be the same.
That is what I see for the moment. The problem is that I do not know what you know. Can you use a vector?
Andy