I have the following problem when I try to run a simple writing to a text file: for the first text file : "alfa.txt" the program works fine, but for the "beta.txt" text file the program stops working and I can't write anything to it. Here is the source code:
Mainly names, and for alfa file it works fine, I write the names, then i hit Ctrl+Z to finish the reading from the keyboard and when I want to do the same thing with beta file (the second while) it won't work. The window turns inactive!
Insert cin.clear(); before while(cin>>ch2) .
After you you pressed Ctrl-Z cin is in eof state. cin.clear(); clears the state and allow to continue work.
At last! It worked ! The problem was my version of C++, I was working on the 3.1 version. Now I've downloaded the 5.2 version and it works like a charm, exactly as you've said - by pressing Enter before and after hitting Ctrl+Z.
I have another question. Now the program works fine and writes the names into the text files. But how can I sort alphabetically the names into the two text files? Can you give me an example?