fork(5) 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. template< typename T>
  12. ostream & operator<< (ostream &, const Matrix<T> &);
  13.  
  14. template< typename T>
  15. istream& operator >> (istream &, Matrix<T> &);
  16.  
  17. template<typename T>
  18. class Matrix
  19. {
  20. private:
  21. T arr[SIZE][SIZE];
  22. friend ostream& operator << <> (ostream &, const Matrix &);
  23. friend istream& operator >> <> (istream &, Matrix &);
  24. void initialize();// функция которая заполняет матрицу как единичную
  25.  
  26. public:
  27. Matrix() {}
  28. Matrix(const Matrix<T>&);
  29. const Matrix& operator=(const Matrix<T>&);
  30. const Matrix& operator*(const Matrix<T>&);
  31. void operator*=(const Matrix<T> &);
  32. T* operator[](int row);
  33. };
  34.  
  35. template< typename T>
  36. ostream & operator<<(ostream & os, const Matrix<T> & rhs)
  37. {
  38. for (int i(0); i < SIZE; ++i)
  39. {
  40. for (int j(0); j < SIZE; ++j)
  41. {
  42. os << rhs.arr[i][j] << ' ';
  43. }
  44. os << endl;
  45. }
  46. return os;
  47. }
  48.  
  49. template< typename T>
  50. istream & operator>>(istream& is, Matrix<T> & rhs)
  51. {
  52. for (int i(0); i < SIZE; ++i)
  53. {
  54. for (int j(0); j < SIZE; ++j)
  55. {
  56. is >> rhs.arr[i][j];
  57. }
  58. }
  59. return is;
  60. }
  61.  
  62. int main()
  63. {
  64. Matrix <int> m;
  65. ifstream("input.txt") >> m;
  66.  
  67. return 0;
  68. }
Success #stdin #stdout 0s 3452KB
stdin
Standard input is empty
stdout
Standard output is empty