473,387 Members | 1,624 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Problem with ios::flags

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
2 1916
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Paul Davis | last post by:
I have some simple test code, which is copied pretty much verbatim from Josuttis (although he doesn't give complete examples): #include <iostream> main() { cout << hex << 1 << endl; std::cout...
8
by: Markus Dehmann | last post by:
My ios::uppercase (and others) seems not to work. #include <iostream> using namespace std; int main(){ int num = 45; cout.setf(ios::hex | ios::showbase | ios::uppercase); cout << "number " <<...
103
by: Steven T. Hatton | last post by:
§27.4.2.1.4 Type ios_base::openmode Says this about the std::ios::binary openmode flag: *binary*: perform input and output in binary mode (as opposed to text mode) And that is basically _all_ it...
1
by: Rohit Raghuwanshi | last post by:
Hello all, we are running a delphi application with DB2 V8.01 which is causing deadlocks when rows are being inserted into a table. Attaching the Event Monitor Log (DEADLOCKS WITH DETAILS) here....
1
by: srikar | last post by:
Hi all, For the class strstream let the object be line. On an 16 bit machine previously of ANSI standard ststream line line.setf(ios::in); What is need for setting the flag to input....
1
by: Alexander Korsunsky | last post by:
Hi! Is it possible to extract the mode flags of a stream (FILE* stream or fstream - object), without looking at how the stream was opened? What I mean by mode flags is wether the stream is opened...
4
by: Nikos Hatzigiannakis | last post by:
The following code does not display the number 10 in hex format. The hex flag doesn't seem to work. Any ideas? Compiler is DEV C++ 4.9.9.2 http://www.bloodshed.net/
6
by: Ralf Goertz | last post by:
Hi, I'd like to use copy() to send the content of an integer container to cout. How can I make sure that /all/ of them are printed with width 2? #include <iostream> #include <iterator> int...
0
by: Fraser Ross | last post by:
"Andre Paim" One that you have missed is <algorithm>. setbuf in basic_streambuf only returns the this pointer. I don't think it is overridden in basic_stringbuf. You are expecting it to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.