By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,061 Members | 1,563 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,061 IT Pros & Developers. It's quick & easy.

Problem with ios::flags

P: n/a
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.
Jun 15 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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
Jun 15 '07 #2

P: n/a
John Harrison escreveu:
Paulo da Silva wrote:
>Hi!
....
>
You mean ILEN-1 chars
Of course ... I mistyped 2 ...
.. 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
{
}
Thanks. Anyway I thought of a flags bit or something and was not sure if
strlen - zero terminated (or gcount()) is implementation independent
for this purpose.
>
Here's a good site that explains exactly what istream::getline does.

http://www.dinkumware.com/manuals/de...tream::getline
Thanks.
Jun 15 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.