Generally, testing for eof() is not good practice - for several reasons, the first of which is that there could be some other (error) condition arising which prevents end of file from being reached.
You could change for example .eof() to .fail() throughout. In fact testing this condition is so common that there is a more concise way of doing so. Instead of writing while (!(masterFile.eof())) the syntax while (masterFile) gives the same effect.
See http://www.cplusplus.com/reference/ios/ios/operator_bool/
In this particular case, most probably one or both the input files was not opened successfully.
1 2 3 4 5 6 7 8 9 10 11 12 13
ifstream masterFile("Master.rxt"); // declare and open the file
if (!masterFile) // check that it was opened
{
cout << "Error opening master file\n";
return 1;
}
ifstream transactionFile("Transaction.rxt"); // declare and open the file
if (!transactionFile) // check that it was opened
{
cout << "Error opening transaction file\n";
return 2;
}
read the first items from each file, then
1 2 3 4
while (transactionFile)
{
while (masterFile && (mClientNumber < tClientNumber))
// etc.
Are you sure your files are actually opening? If the file fails to open or some other failure happens eof() will never happen. And you really shouldn't be using eof() to control your read loops, this can lead to problems such as extra data appearing to be read. Instead use the actual read operation to control the read loops.
By the way there is no EOF character with modern operating systems, EOF is a condition not a character.
Also please post a small sample of your input file.
It was actually not opening the files since in the previous code I had .rxt when the files were saved as .rtf Yes... beginner mistake.
now the program runs perfectly
Thank You so much for all your help!!! :)
.. or appears to. Just a reminder, the use of eof() can be fragile and give rise to several different problems, such as processing the last line or entry in the file twice. It is not recommended.