ofstream out{ outputFileName };
if (!out)
{
ostringstream os;
os << "Cannot open file '" << outputFileName << "'";
throw ios_base::failure{ os.str() };
}
for ( auto& r = m_rows.begin(); r != m_rows.end(); ++r)
{
for (auto& c = r->begin(); c != r->end(); ++c)
{
out << *c;
if (next(c) != r->end())
{
out << ",";
}
}
out << endl;
}
out.flush();
out.close();
}
You're not checking to see that the actual writes don't fail. You should do that every time you write, or else call the exceptions member function on it. You'll be able to tell better by seeing what the error state is.
What is m_rows? Are you sure it actually contains some data?
Also you may want to consider a couple of ranged based loops for your output section:
1 2 3 4
for(auto& rows : m_rows)
for(auto& cols : rows)
out << cols << ", " ;
out << endl;
By the way you don't need either the flush() or the close() calls. The destructor will automatically call these functions when the instance goes out of scope.