Allowing user to choose between to different files

I'm trying to make part of a program so that it allows the user to choose between to files.
This is what I initially had:

cout << "Which data file would you like to use?" << endl;
cout << "1. FORCES1.txt" << endl;
cout << "2. FORCES2.txt" << endl;
cout << "Enter 1 or 2: ";
cin >> choice;
switch (choice)
{
case 1:
ifstream infile ("R:\\FORCES1.txt");
break;
case 2:
ifstream infile ("R:\\FORCES2.txt");
break;
default:
cout << "Invalid response. Program terminated." ;
}

if (infile.fail())
{
cout << "Error. Unable to read file" << endl;
return 0;
}

else
{
continues....


----------------------------------------------------------------------------
I keep getting errors for this.
Another thing is, I need to be able to open whichever file the user chooses, and go on with the rest of my program.
Maybe I'm supposed to use continue instead of [b]break[/], but I've never used continue before.
Try declare infile before the switch.
1
2
3
4
5
6
7
8
9
10
11
12
ifstream infile;
switch (choice)
{
case 1:
	infile.open("R:\\FORCES1.txt");
	break;
case 2:
	infile.open("R:\\FORCES2.txt");
	break;
default:
	cout << "Invalid response. Program terminated." ;
}
I did this, and here are the errors I'm getting:


In function 'int main()'
37 jump to case label
35 crosses initialization of 'std::ifstream infile'
38 redeclaration of 'std::ifstream infile'
35 'std::ifstream infile' previously declared here
40 jump to case label
35 crosses initialization of 'std::ifstream infile'
37 [Warning] destructor needed for 'infile'
37 [Warning] where case label appears here
37 [Warning](enclose actions of previous case statements requiring destructors in their own scope.)
40 [Warning]destructor needed for 'infile'
40 [Warning] where case label appears here
Carefully read my previous post again.
Sorry about that. It worked. Thanks.
Topic archived. No new replies allowed.