Something is wrong with my program logic. I am trying to merge to files into one. The program starts, but nothing happens, it doesn't close, and the mergefile doesn't update. v.v
The first file is FemaleClients.rtf and consists of these characters:
21 Barbara_Jones
82 Sue_Todd
275 Mary_Donald
276 Cathy_Conner
300 Debbie_Baker
400 Kim_Tanner
The second file, MaleClients.rtf, consists of:
56 Bob_Johnson
100 Dan_Smith
200 Mike_Tay
They are supposed to merge into MergedClients.rtf. If you can find the error in the logic without creating those folders, awesome. If not, I understand it would take awhile to create these folders and go through trial and error. Anywho, heres my code. Don't laugh.
Thank you for noticing. Fixed it, and the program still doesn't close. Also, now when I open the .txt file, it says "boolean inWritten2" and then displays a zillion "0's". When I open the rtf file, still no merge :(
Line 49,61,66
take out the comma ',' and replace with appropriate '<<" or '>>'
You cannot use comma
And also there is a major error in your code. look at the while loop braces'{}'
The closing braces at line 58. The while loop will finish there. So take out that closing brace
The logic is a little mind boggling, is there any special requirements for the merged file? if not.. keep it simple,
1 2 3 4 5 6
// you mention rtf, though you are opening txt files.. is this correct?
ifstream male_clients("MaleClients.txt");
ifstream female_clients("FemaleClients.txt");
ofstream merged_clients("MergedClients.txt")
merged_clients << male_clients.rdbuf() << female_clients.rdbuf();
Well, this logic is given to my class in an algorithm and we are supposed to transfer it to c++ statements. I'm pretty new to programming, so I probably couldn't write better logic anyways...
Here is my new code, program still doesn't work. I'm curious to what the statement "merged_clients << male_clients.rdbuf() << female_clients.rdbuf();"
does, couldn't find a straight forward explanation from google.
I'm curious to what the statement "merged_clients << male_clients.rdbuf() << female_clients.rdbuf();"
ios::rdbuf() returns a pointer to the stream buffer, and ostream::operator<< has an overload to output stream buffers. Internally, you could picture it as while loop reading and writing each character to the output stream.
ProductFailure wrote:
Well, this logic is given to my class in an algorithm and we are supposed to transfer it to c++ statements.
In that case, disregard the code from previous post.
Lines 34, 42, 49, 54, output a space between the number and name. Line 49 missing an endl. Line 58 missing !. !(inFile2.eof())