Hello everyone,
I am taking my first class in C++ and I have run into some errors while trying to write a file handling and application program. I thought I was doing good until I ran the compiler. The first error appears on the line (84) second on line (91). I read my book and tried to write the code. Could someone tell me if I converted the pseudocode correctly to source code for these two lines (84) and (91)? I see errors 110, 116, 122. I don't understand what is meant by "no match" or how to fix it. Any help would be greatly appreciated. Thank you for your time.
84 expected unqualified-id before '(' token
91 expected unqualified-id before '(' token
110 no match for 'operator!=' in 'inFile1 != -0x000000001'
116 no match for 'operator!=' in 'inFile2 != -0x000000001'
122 no match for 'operator==' in 'inFile1 == -0x000000001'
122 no match for 'operator==' in 'inFile2 == -0x000000001'
Thanks for looking at the code but I am totally confused. Could you please clarify. I am not sure how to rewrite it. Also do you know why I am get this error code "expected unqualified-id before '(' token " on the lines (84) and (91). Thanks for your time.
I believe that the .EOF() that you're using in lines 84 and 91 is not actually a function, but rather a variable, so just remove the () and you should be good.
Edit: As for the other problems, instead of putting inFile1 != EOF, put !inFile1.EOF. Change every case appropriately and it should work.
Thanks for looking at the code. I have change my source code to the following but I am still receiving the following error. I have tried all that I know and can't seem to get it right. Thanks again for your time.
30 expected unqualified-id before '(' token
37 expected unqualified-id before '(' token
56 expected unqualified-id before '(' token
62 expected unqualified-id before '(' token
68 expected unqualified-id before '(' token
68 expected unqualified-id before '(' token
Thank you for looking into my problem vichu8888. I able able to compile now and when the program runs I only receive the Client numbers and names from the female client in the merged file. Might you have a reason why this would happen? Thank you for your time.
The question reads
" The Cupid Matchmaking Service maintains two files--one for male clients and another for female clients. Each file contains a client ID, last name, first name, and address. Each file is in client ID number order. Design the logic for a program that merges the two files into one file containing a list of all clients, maintaining ID number order."
The address have been left out. Thanks again for your time vichu8888. I do appreciate it.
#include <fstream>
#include <iostream>
#include <cstdlib>
#include <string>
usingnamespace std;
int main()
{
//declared four ifstream variables because two(i1,i2) used for getting the length of the file
//two(in1,in2) for calcualtions purposes
ifstream i1,i2,in1,in2;
ofstream out;
//Variable declrations
int male_id, female_id;
string male_name, female_name;
int len1=0;//Initialising male file length
int len2=0;//initialising female length
cout << "File merge processing starting" << endl;
i1.open("MaleClients.rtf");
i2.open("FemaleClients.rtf");
out.open("MergeClients.rtf");
//Calculating male file length
while(!i1.eof())
{
i1>>male_id>>male_name;
len1++;
}
//Calcualting female file length
while(!i2.eof())
{
i2>>female_id>>female_name;
len2++;
}
//Checking the file length by outputting the both lengths
cout<<"Male file length: " <<len1<<" || Female File length: "<<len2<<endl;
//opening input files for calculations purposes
in1.open("MaleClients.rtf");
in2.open("FemaleClients.rtf");
if(len2>len1)//Condition true when female file length is greater
{
while(!in2.eof())//read until eof of feamle file
{
in2>>female_id>>female_name;//read first set of input from female data
if(!in1.eof())//if male file havent reached end of file,loop executes
{
in1>>male_id>>male_name;//read the male data
//This condition is to check whose ID is greater and print accordingly
if(male_id<female_id)
{
out<<male_id<<" "<<male_name<<endl;
out<<female_id<<" "<<female_name<<endl;
}
else
{
out<<female_id<<" "<<female_name<<endl;
out<<male_id<<" "<<male_name<<endl;
}
}
//If the male input data file finished, it just read female data and write to the file
else
out<<female_id<<" "<<female_name<<endl;
}
}
else
//Here you can write the code when len1>len2 i.e) when male data file have more members than female
//just copy and paste the above code here and change male data's to feamle data's and vice versa
i1.close();
i2.close();
in1.close();
in2.close();
out.close();
cout << "Merging Complete" << endl;
system("PAUSE");
return 0;
}
I have given the comments too, If you dont understand please let me know which part
Thanks for taking the time to look over this. The only thing is my instructor gives us the pseudocode and then we have to write the program from what he gives us. I'm impressed with how fast you wrote this code. Were you able to see what was causing the problem in my code. The only reason I am asking is because I have to turn in the program as he wrote it. I can't thank you enough for all the time you have spent on this with me.
Try this. I followed the pseudocode you have given. Now it works perfect. You got confused with !infile.eof() and infile,eof(). while(!infile.eof(){} - This while loop continues until end of file is reached while(infile.eof()){}- This while executes only if the end of the file is reached
Apart from that, there were several minor errors with braces for '{}' if else condition. After correcting all those, the program worked.
I didnt see your pseudocode at first. When I read two line of it, I thought it was your try out. So I just skipped it. Otherwise this will be done few hours before itself