Hi, i've trying to make a program that reads data for a matrix and print the data for it. I can get the ostream operator to work, however the istream operator wont work. Any got some ideas to help me sort out the istream operator:
This is my header file:
#ifndef MATRIX_H
#define MATRIX_H
#include <iostream>
using namespace std;
class Matrix{
private:
int ** value;
int row;
int colum;
public:
Matrix();
Matrix(int ro, int col);
Matrix(const Matrix& org);
//Operator
friend istream& operator>>(istream& in, Matrix& ho);
friend ostream& operator<<(ostream& out, const Matrix& ho);
};
#endif
This is my .cpp file:
#include "Matrix.h"
#include <iostream>
using namespace std;
Matrix::Matrix(int ro, int col){
row = ro;
colum = col;
value = new int*[row];
for (int i = 0; i < row; i++){
value[i] = new int[colum];
}
}
Matrix::Matrix(const Matrix& org)
value = new int*[row];
for (int i = 0; i < row; i++){
vaule[i] = org.value[i];
for(int j = 0; j < colum;i++){
value[j] = org.value[j];
}
}
}
//Here are where the problems starts.
istream& operator>>(istream& in, Matrix& ho){
int line; // I'm not sure what the input should be when i'm trying to put it in a value pointer that points to a
// table of data.
in >> line;
for(int i = 0; i < ho.row; i++){
for (int j = 0; j < ho.colum; j++){
ho.value[j] = line[j];
}
}
return in;
}
ostream& operator<<(ostream& out, const Matrix& ho){
ut << '[';
for (int i=0;i < ho.row; i++){
for (int j = 0; j < ho.colum; j++){
if(i == 0 && j == 0){
ut << ho.value[0];
}
else{
ut << ',' << ho.value[j];
}
}
}
ut << ']';
return ut;
}
So the problem is that i cant get the input to work. When i compile it there is allways different errors. what ever i try. Maybe i think the wrong way. But the main thing is that i have a double pointer. That points to a table which is the colums which then points to a new table that have the rows. Thats how the assignment is.
Thanks in advance.
Regards Barvik