I am extracting each full row of a csv file using std::getline
:
for (std::string row; std::getline(is, row); ) // reads entire row in csv file
{
if (std::ranges::count(row, ',') != Temp_reading::read_parameters - 1) // checks if row has right amount of columns
{
std::cerr << "Row: " << row << " contains too many columns in csv file" << "n";
is.unget(); // Want this to put entire row back into istream
is.clear(std::ios_base::failbit);
return;
}
// does other stuff if the row has right amount of columns
}
In this case is.unget()
will only put back the last character in the istream. Is there a way to make is.unget()
put back the entire row? Or is there another simple way to achieve the same?