cout and perror

P

puzzlecracker

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
 
J

Jonathan Mcdougall

puzzlecracker said:
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
 
R

red floyd

puzzlecracker said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top