I have an input from isstream
1 2
3 4
5 6
I would like to populate this from isstream overloading the >>
operator
the input would be something like
Matrix m;
string input = "1 2 \n 3 4\n 5 6\n";
istringstream ss(input);
ss >> m;
how do I implement the >>
operator to parse the matrix from isstream?
I have tried the code below but the peek call seems to ignoring the new line
std::istream& operator>>(std::istream& is, Matrix& s)
{
vector<vector<int>> elements;
int n;
while (!is.eof())
{
vector<int> row;
while ((is.peek() != '\n') && (is >> n))
{
row.push_back(n);
}
is.ignore(numeric_limits<streamsize>::max(), '\n');
elements.push_back(row);
}
return is;
}