Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > cout and perror

Reply
Thread Tools

cout and perror

 
 
puzzlecracker
Guest
Posts: n/a
 
      10-22-2005
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

 
Reply With Quote
 
 
 
 
Jonathan Mcdougall
Guest
Posts: n/a
 
      10-22-2005
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

 
Reply With Quote
 
 
 
 
red floyd
Guest
Posts: n/a
 
      10-22-2005
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.
 
Reply With Quote
 
Branimir Maksimovic
Guest
Posts: n/a
 
      10-22-2005

"puzzlecracker" <> wrote in message
news: 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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: cout vs std::cout Hendrik Schober C++ 7 10-07-2008 12:02 AM
Re: cout vs std::cout Stefan Ram C++ 7 09-30-2008 01:55 PM
can cout<<""; can cout<<""; contribute ? wangzhihuii@yahoo.com.cn C++ 4 09-15-2005 06:16 PM
std::cout vs cout Pmb C++ 2 06-02-2004 03:27 PM
man cout or info cout abi C++ 2 06-28-2003 06:42 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57