1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
#include <iostream>
#include <fstream>
#include <vector>
#include <iomanip>
using namespace std;
void read_data(ifstream& , vector <vector <int> >&, int, int );
void print_data(const vector <vector<int> >&, int, int);
int main()
{
int no_rows = 5;
int no_cols = 10;
vector<vector<int>> A(no_rows, vector<int>(no_cols));
ifstream infile;
infile.open("matrix_1.dat");
read_data(infile, A, no_rows, no_cols);
print_data(A, no_rows, no_cols);
}
void read_data(ifstream& is, vector <vector <int> >& m, int ROWS, int COLS)
{
int temp = 0;
for (int row = 0; row < ROWS; row++)
{
for (int col = 0; col < COLS; col++)
{
is >> temp;
m[row][col] = temp;
}
}
}
void print_data(const vector <vector<int> >& m, int ROWS, int COLS)
{
for (int i = 0; i < ROWS; i++)
{
for (int j = 0; j < COLS; j++)
{
cout << std::setw(6) << m[i][j];
}
cout << endl;
}
}
|