Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //============================================================================================================
- // getFileName takes a file stream object by reference, and after asking the user for input via a numeric
- // choice, executes a switch block, opening 1 of 3 files.
- //
- // I wanted to have the user type a file name, literally. For example, the user would type "numbers1.txt". I
- // wanted that to go into a string, and then call file.open(string);. However as far as I know and from my
- // little research on the internet, it turns out ".open()" only takes a string literal as an argument. So I had
- // to take the easy way out and just make a switch statement whose .open() function calls already have string
- // literals.
- // I am not happy with this answer. I want the user to be able to drop any text file into the right folder
- // and have the program use it. For example, "clownsandballoons.txt". But until I find out how to do that, this
- // is as good as I can do.
- //============================================================================================================
- void getFileName(ifstream &file)
- {
- int choice;
- cout << "Enter 1 to open numbers1.txt, 2 to open numbers2.txt, and 3 to open numbers3.txt\n\t";
- while(cin >> choice, (choice > 3 || choice < 1))
- {
- cout << "Enter 1, 2 or 3.\n\t";
- cin >> choice;
- }
- switch(choice)
- {
- case 1:
- file.open("numbers1.txt");
- break;
- case 2:
- file.open("numbers2.txt");
- break;
- case 3:
- file.open("numbers3.txt");
- break;
- }
- return;
- }
Add Comment
Please, Sign In to add comment