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 variablefin before the switch statement and open the file like this:
fin.open("....");
William Hemsworth
Posting Virtuoso
1,591 posts since Mar 2008
Reputation Points: 1,429
Solved Threads: 129