This is my first post here.
I would like to know that is it possible to accomplish:
I have Matrix class and two objects with rows, columns and entries set to zero. Then lets say I overload the extraction and insertion operator to take input and show output.
void test_input_output_self_consistency(size_t rows, size_t cols)
{
std::cout << "Test_input_output_self_consistency";
Matrix m1(rows, cols, 0);
Matrix m2(rows, cols, 0);
for (size_t i = 0; i < rows; ++i)
{
for (size_t j = 0; j < cols; ++j)
{
m1(i, j) = (j * 100 + i) / 9.0;
}
}
std::stringstream ss;
ss << m1;
ss >> m2; // checking if your operator>> can parse your own output generated by operator<<
assert("check output and input operator" && almostEqual(m1, m2, 1e-4));
}
I am interested here:
std::stringstream ss;
ss<<m1;
ss>>m2;
// checking if your operator>> can parse your own output generated by operator<<
Implementation for iostream >> and ostream << is simple which takes input and shows output respectively. Thanks in advance
Aucun commentaire:
Enregistrer un commentaire