First, I should point out a problem in the code, your iss
is in the fail state after reading the first line and then calling while(getline(iss, entry, ';'))
, so after reading every line you need to reset the stringstream
. The reason it is in the fail state is that the end of file is reached on the stream after calling std:getline(iss, entry, ';'))
.
For your question, one simple option is to simply check whether anything was read into entry
, for example:
stringstream iss;
while(getline(file, line)) {
iss << line; // This line will fail if iss is in fail state
entry = ""; // Clear contents of entry
while(getline(iss, entry, ';')) {
// Do something
}
if(entry == "") // If this is true, nothing was read into entry
{
// Nothing was read into entry so do something
// This doesn't handle other cases though, so you need to think
// about the logic for that
}
iss.clear(); // <-- Need to reset stream after each line
}