I am trying to close this file so that it stops reading the array twice. i have placed it in different places but i does not seem to work, please look at my code and advise me on were to place the infile.close() Thanks in advance
#include <iostream>
#include <fstream> // FILE I/O
#include <stdlib.h> // STANDARD
#include <iomanip>
using namespace std;
//
// PROTOTYPE STATEMENTS
//
void function_name();
//
// GLOBAL VARIABLE DECLARATIONS
//
const int SIZE = 10;
int sum = 0;
int main()
{
int two_di_arr[ SIZE ][ SIZE ];
ifstream infile("Two_Dimensional_Data_In.txt");
for( int row = 0; row < SIZE; row++ )
{
int sum = 0;
for( int col = 0; col < SIZE; col++ )
{
infile >> two_di_arr[ row ][ col ];
sum += two_di_arr[ row ][ col ];
cout << setw( 6 ) << two_di_arr[ row ][ col ] << " ";
}
cout << sum;
cout << endl;
}
infile.close();
//////////////////////////////////////////////////////////////////
for( int row = 0; row < SIZE; row++ )
{
for( int col = 0; col < SIZE; col++ )
{
int sum = 0;
infile >> two_di_arr[ row ][ col ];
sum += two_di_arr[ col][ row];
cout << setw( 6 ) << two_di_arr[ row ][ col ] << " ";
}
cout << sum;
cout << endl;
}
system("pause");
return 0;
}
// END MAIN() //////////////////////////////
// FUNCTION DEFINITIONS
void function_name()
{
}
<< moderator edit: added [code][/code] tags >>