Paulo da Silva wrote:
Hi!
Please consider the following fragment
std::cin.exceptions(std::ios::failbit);
...
try
{ is.getline(p,ILEN);
...
}
catch (std::ios::failure const &problem)
{ if (WHAT HERE?)
{ // '\n' not found yet
}
else
{ // Real failure
}
}
How do I tell a real failure from just ILEN-2 chars already read but not
yet '\n'?
Thanks for any help.
You mean ILEN-1 chars. If the fail bit is set there will either be
ILEN-1 chars or zero chars (not counting the null terminator) in p. So
you can test for that.
if (strlen(p) == ILEN-1)
{
}
else
{
}
Here's a good site that explains exactly what istream::getline does.
http://www.dinkumware.com/manuals/de...tream::getline
It you haven't considered it already you should defintely think about
switching to the string version of getline
http://www.dinkumware.com/manuals/de...2.html#getline
Might be no need to treat long lines as a special case then.
john