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

cout and perror

P: n/a
In one of my applications, I was mixing perror (cerrno )with
cout(iostream) calls and sometimes getting unordered output. The exact
context was to print an error condition as well as cause for
exceptions. Therefore, I resorted to .flush call in iostream that did
the trick. Anyone can explain the root of all evil in intermixing the
c++ with date c library, perhaps, give a link to where solutions to
this problem are addressed?
Why don't file related exception don't have a error message that would
indicatate the exact reason for a failure and stack trace?
Thanks

Oct 22 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
puzzlecracker wrote:
In one of my applications, I was mixing perror (cerrno )with
cout(iostream) calls and sometimes getting unordered output. The exact
context was to print an error condition as well as cause for
exceptions. Therefore, I resorted to .flush call in iostream that did
the trick. Anyone can explain the root of all evil in intermixing the
c++ with date c library, perhaps, give a link to where solutions to
this problem are addressed?
Well googling for "mixing cout and printf" yields some pretty good
results. Is it so hard to search a bit before asking a question?
Why don't file related exception don't have a error message that would
indicatate the exact reason for a failure and stack trace?


Because the "exact reason" can be pretty much anything because a C++
application can run on pretty much anything. It is impossible to have
error codes for every possible error, that's why it depends on the
implementation.

As for having error messages, I much prefer as a developper to have an
error code than a message. What about internationalization, for
example?

If it is only for debugging, most compilers will provide some ways to
retrieve error messages on a system (such as GetLastError() and
FormatMessage() on Win32), but since these are non-standard, you should
ask on a newsgroup supporting your implementation.
Jonathan

Oct 22 '05 #2

P: n/a
puzzlecracker wrote:
In one of my applications, I was mixing perror (cerrno )with
cout(iostream) calls and sometimes getting unordered output. The exact
context was to print an error condition as well as cause for
exceptions. Therefore, I resorted to .flush call in iostream that did
the trick. Anyone can explain the root of all evil in intermixing the
c++ with date c library, perhaps, give a link to where solutions to
this problem are addressed?
Why don't file related exception don't have a error message that would
indicatate the exact reason for a failure and stack trace?
Thanks


Use strerror(). That way you can format your output more precisely anyways.
Oct 22 '05 #3

P: n/a

"puzzlecracker" <ir*********@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...


Why don't file related exception don't have a error message that would
indicatate the exact reason for a failure and stack trace?


In this case boost is a must:
http://www.boost.org/libs/iostreams/...xceptions.html

Greetings, Bane.
Oct 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.