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
| #include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
using namespace std;
class Matrice
{
unsigned int num_lines;
unsigned int num_columns;
vector<int> data;
public:
Matrice(unsigned int lines, unsigned int columns, unsigned int init_value) :
num_lines(lines), num_columns(columns), data(lines * columns,
init_value){}
int& operator()(unsigned int line, unsigned int column)
{ return data[line * num_columns + column]; }
friend ostream& operator<<(ostream& os, Matrice const& m);
};
ostream& operator<<(ostream& os, Matrice const& m)
{
unsigned int index_column = 0;
for_each(begin(m.data), end(m.data),[&](int e){
index_column++ % m.num_columns != 0 ? os << e << " " : os << endl << e << " ";
});
return os;
}
int main()
{
fstream file("test.txt"); // voir 1)
Matrice m(10, 10, 0);
unsigned int c0, c1, c2;
while (file >> c0 >> c1 >> c2) // voir 2) puis 3)
++m(c1, c2);
cout << m;
return 0;
} |
Partager