"Write a program that will create userids for email addresses of a company. Names of employees will be contained in a file. Your task is to read the file character by character."
- input file: "employee.dat" has the following names = SS van der Merwe;PJ Ferreira;HW du Plessis;DF Kodisang;AA Papoudopolous;G Mhlanga;TRF Schoeman;LJ Marais-Le Roux;CG Roux;B Nicholaidis;TT Tshabalala;RV Mississipi;
When the user enters any of those names, the output should be a user ID, for example: SS van der Merwe = ssvandme.
My program is able to ask for a name but it just doesn't save anything to the output file, userid.dat. Please help.
You open a file, but you never try writing to it. Here is a small snippet of a program I wrote, that saves data to a file. Use it to make changes to your code.
1 2 3 4 5 6 7 8
ofstream SaveFile;
SaveFile.open("Mystery Mania Clues.txt");
SaveFile << "Mystery Mania Clues" << endl << endl;
for (int x = 0; x < 8; x++)
SaveFile << s$[x] << endl;
SaveFile.close();
Andy:
You really should try to avoid the C function exit(), it doesn't know about C++ classes and can cause data loss if used inappropriately. Since this is C++ start thinking about using exceptions when you need to "abort" the program.
You should also start thinking about using RAII techniques, which in this case, means letting the destruction of objects be done automatically, the stream.close() functions should be rarely needed let the destructor do it's job when the instance goes out of scope.