cout and perror

Discussion in 'C++' started by puzzlecracker, Oct 22, 2005.

  1. 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
     
    puzzlecracker, Oct 22, 2005
    #1
    1. Advertising

  2. 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
     
    Jonathan Mcdougall, Oct 22, 2005
    #2
    1. Advertising

  3. puzzlecracker

    red floyd Guest

    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.
     
    red floyd, Oct 22, 2005
    #3
  4. Branimir Maksimovic, Oct 23, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. abi

    man cout or info cout

    abi, Jun 27, 2003, in forum: C++
    Replies:
    2
    Views:
    1,675
  2. Pmb

    std::cout vs cout

    Pmb, Jun 2, 2004, in forum: C++
    Replies:
    2
    Views:
    4,451
    Leor Zolman
    Jun 2, 2004
  3. Replies:
    4
    Views:
    344
    Howard
    Sep 15, 2005
  4. Stefan Ram

    Re: cout vs std::cout

    Stefan Ram, Sep 28, 2008, in forum: C++
    Replies:
    7
    Views:
    513
  5. Hendrik Schober

    Re: cout vs std::cout

    Hendrik Schober, Sep 28, 2008, in forum: C++
    Replies:
    7
    Views:
    464
    Jerry Coffin
    Oct 7, 2008
Loading...

Share This Page