(I originally submitted this as a comment in Solution 1, but it wouldn't format properly.)
The easiest way to avoid empty strings in the vector is not to put them there in the first place:
while(getline(sjp2,s))
{
if(!s.empty() && (s.back() == '\r')) s.pop_back();
if(!s.empty()) L2.push_back(s);
}
That
pop_back
line is in case the file you're reading was created on Windows but is being read on Linux. Windows adds
"\r\n"
at the end of a line, whereas Linux only adds
'\n'
. It is therefore necessary to strip out the
'\r'
. You can remove that line unless you need to handle that scenario.