View Single Post
Join Date: Mar 2008
Posts: 1,383
Reputation: William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of 
Solved Threads: 112
Sponsor
William Hemsworth William Hemsworth is offline Offline
Nearly a Posting Virtuoso

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

 
0
  #3
Jul 2nd, 2008
The variable fin is destructed before you use it. For this to work you would have to arrange it slightly differently.

switch( choose )
	{
	case 1:
		// Constructor that opens the file
		ifstream fin("madlip1.txt");

		// If statement to check if the file can be opened or not.
		if( !fin )
		{
			cerr << "\nError, Can't open the File.!\n";
			exit(1);

		} // end if statement
	
	break; // to exit switch

	case 2:
		// Constructor that opens the file
		ifstream fin("madlip2.txt");

		// If statement to check if the file can be opened or not.
		if( !fin )
		{
			cerr << "\nError, Can't open the File.!\n";
			exit(1);

		} // end if statement

		break; // to exit switch loop

	} // end switch

	int i =0; // Initiate this variable for the use of the array.

	// While Loop to read the File, and save the content in the array


	// Too late, its already been destructed
	while( fin>>x )
	{
		A[i] = x;
		i++;
	}

for this to work, construct the variable fin before the switch statement and open the file like this:
fin.open("....");
I need pageviews! most fun profile ever :)
Reply With Quote