> 3. I want it open when the user typed open and pressed enter.

You need to open a file before you can do anything with it. You cannot write data to a file that is not open (for writing).
So if the 1.2.3 above indicates the sequence of events the program should follow, then you need to keep the entered data in memory until the user types "open" to get the file open.
Only when the file is open can you enter data. So you need to move the a_file<<"number :" <<x ;
and the alphabets one to AFTER you've opened the file.

Because contrary to your design what you've actually got is:
1. open the file
2. get some numbers and write them to the file
3. get some alphabets and write them to the file
4. prompt for "open"
5. ...and now your code gets really confused (and I think you do too) because somehow you've forgotten that you've already opened the file and written the data to it.
The loop loops until the user enters "open".
If they don't then it keeps looping.
If they do it opens the file (WHICH IS ALREADY OPEN), and the break ends the loop.
After exiting the loop you then close the file (so I'm uncertain of the point of the loop - it seems to achieve absolutely nothing)

Last edited by xpi0t0s; 14Mar2009 at 14:28..