View Single Post
Join Date: Nov 2005
Posts: 251
Reputation: dwks has a spectacular aura about dwks has a spectacular aura about 
Solved Threads: 25
dwks's Avatar
dwks dwks is offline Offline
Posting Whiz in Training

Re: How to make a choise for the user to choose a file to open?

 
0
  #4
Jul 2nd, 2008
In order to use the ifstream fin variable that you declare inside the switch statement, you need to declare it outside the switch statement. For example:
  1. ifstream fin;
  2. switch(choose) {
  3. case 1:
  4. fin.open("whatever.txt");
  5. // ...
  6. }
  7.  
  8. while(fin >> whatever) // ...

[edit] Wow, I was beaten by over half an hour. Sorry.

Just one other thing to add: why not let the user enter the name of the file themselves? That way you don't have to worry about the switch statement or anything . . . . [/edit]
Last edited by dwks; Jul 2nd, 2008 at 5:20 pm.
dwk

Seek and ye shall find.

"Only those who will risk going too far can possibly find out how far one can go."
-- TS Eliot.

"I have not failed. I've just found 10,000 ways that won't work."
-- Thomas Alva Edison

"The only real mistake is the one from which we learn nothing."
-- John Powell
Reply With Quote