I am working on a project that involves reading in a SparseMatrix
using the >> operator and I had a question.
In our example code, it wants us to read a SparseMatrix
in from a file by using the input operator, an example being:
SparseMatrix m;
infile >> m;
My question is when I am overloading the input operator for my SparseMatrix
class, can I do something like this:
std:: istream& operator>>(std::istream &in, SparseMatrix &m) {
int rowIn, colIn;
double dataIn;
string line;
while(in >> line) {
if(line.sizeof() == 3) {
cin >> rowIn;
cin >> colIn;
cin >> dataIn;
SparseMatrix(rowIn, colIn, dataIn);
}
else {
SparseMatrix();
}
}
return in;
}
Or can I not do it that way? I can include any extra code needed, just ask. I just tried to keep it short so this isn't a wall of text. Any help would be appreciated :)