fork(4) download
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. const size_t SIZE =4;
  7.  
  8. template<typename T>
  9. class Matrix
  10. {
  11. private:
  12. T arr[SIZE][SIZE];
  13. template <typename T1> friend ostream& operator << (ostream &, const Matrix<T1> &);
  14. template <typename T1> friend istream& operator >> (istream &, Matrix<T1> &);
  15. void initialize();// функция которая заполняет матрицу как единичную
  16.  
  17. public:
  18. Matrix() {}
  19. Matrix(const Matrix<T>&);
  20. const Matrix& operator=(const Matrix<T>&);
  21. const Matrix& operator*(const Matrix<T>&);
  22. void operator*=(const Matrix<T> &);
  23. T* operator[](int row);
  24. };
  25.  
  26. template< typename T>
  27. ostream & operator<<(ostream & os, const Matrix<T> & rhs)
  28. {
  29. for (int i(0); i < SIZE; ++i)
  30. {
  31. for (int j(0); j < SIZE; ++j)
  32. {
  33. os << rhs.arr[i][j] << ' ';
  34. }
  35. os << endl;
  36. }
  37. return os;
  38. }
  39.  
  40. template< typename T>
  41. istream & operator>>(istream& is, Matrix<T> & rhs)
  42. {
  43. for (int i(0); i < SIZE; ++i)
  44. {
  45. for (int j(0); j < SIZE; ++j)
  46. {
  47. is >> rhs.arr[i][j];
  48. }
  49. }
  50. return is;
  51. }
  52.  
  53. int main()
  54. {
  55. Matrix <int> m;
  56. ifstream("input.txt") >> m;
  57.  
  58. return 0;
  59. }
Success #stdin #stdout 0s 3408KB
stdin
Standard input is empty
stdout
Standard output is empty