Please help on ostream output error

Discussion in 'C++' started by Zhixin Han, Oct 5, 2004.

  1. Zhixin Han

    Zhixin Han Guest

    Hi,

    I got a problem while using the ostream operator to print a trace
    message. Normally it is printing something like this:

    [Oc: 0 Rk: 1]

    The code is:

    os << " [Oc: " << CpName.getOcc() <<" Rk: " << CpName.getRank() <<
    "]";

    But I saw the following outputs, with the characters "Rk: #]" at the
    end of line messed up in different manners:

    Wrong output #1:
    [Oc: 0 Rk:

    Wrong output #2:
    [Oc: 0 R 1]

    Wrong output #3:
    [Oc: 0 Rk2]

    Wrong output #4:
    [Oc: 0 : 2]

    I am wondering how can this happen. Could this be caused by memory
    problem? How can I prevent this from happening?

    Thanks.


    Zhixin
     
    Zhixin Han, Oct 5, 2004
    #1
    1. Advertising

  2. Zhixin Han wrote:
    > I got a problem [...]
    >
    > I am wondering how can this happen. Could this be caused by memory
    > problem? How can I prevent this from happening?


    This is described in the FAQ 5.8. You can find FAQ in the link below

    http://www.parashift.com/c -faq-lite/

    Victor
     
    Victor Bazarov, Oct 5, 2004
    #2
    1. Advertising

  3. Zhixin Han

    Zhixin Han Guest

    Victor Bazarov <> wrote in message news:<v9y8d.3985$09.us.to.verio.net>...
    > Zhixin Han wrote:
    > > I got a problem [...]
    > >
    > > I am wondering how can this happen. Could this be caused by memory
    > > problem? How can I prevent this from happening?

    >
    > This is described in the FAQ 5.8. You can find FAQ in the link below
    >
    > http://www.parashift.com/c -faq-lite/
    >
    > Victor


    Thanks. CpName::getOcc() and CpName::getRank() are defined as:

    const short int getOcc() const {return _occ; }
    const short int getRank() const {return _rank;}
     
    Zhixin Han, Oct 6, 2004
    #3
  4. Zhixin Han wrote:
    > Victor Bazarov <> wrote in message news:<v9y8d.3985$09.us.to.verio.net>...
    >
    >>Zhixin Han wrote:
    >>
    >>>I got a problem [...]
    >>>
    >>>I am wondering how can this happen. Could this be caused by memory
    >>>problem? How can I prevent this from happening?

    >>
    >>This is described in the FAQ 5.8. You can find FAQ in the link below
    >>
    >>http://www.parashift.com/c -faq-lite/
    >>
    >>Victor

    >
    >
    > Thanks. CpName::getOcc() and CpName::getRank() are defined as:
    >
    > const short int getOcc() const {return _occ; }
    > const short int getRank() const {return _rank;}


    You probably didn't understand what the FAQ says. Do I need to explain?
    You are supposed to post the _minimal_ _complete_ _compilable_ code that
    still produces the error you're asking about. It is not enough to see
    the output statement, two member functions and the wrong output. Do you
    understand "not enough"? Post the _complete_ program with the effect
    you are seeing. Then we can discuss a possible cause and solutions. We
    are not mind readers here.

    V
     
    Victor Bazarov, Oct 6, 2004
    #4
  5. Zhixin Han

    Zhixin Han Guest

    Victor Bazarov <> wrote in message news:<iNT8d.4028$09.us.to.verio.net>...
    > Zhixin Han wrote:
    > > Victor Bazarov <> wrote in message news:<v9y8d.3985$09.us.to.verio.net>...
    > >
    > >>Zhixin Han wrote:
    > >>
    > >>>I got a problem [...]
    > >>>
    > >>>I am wondering how can this happen. Could this be caused by memory
    > >>>problem? How can I prevent this from happening?
    > >>
    > >>This is described in the FAQ 5.8. You can find FAQ in the link below
    > >>
    > >>http://www.parashift.com/c -faq-lite/
    > >>
    > >>Victor

    > >
    > >
    > > Thanks. CpName::getOcc() and CpName::getRank() are defined as:
    > >
    > > const short int getOcc() const {return _occ; }
    > > const short int getRank() const {return _rank;}

    >
    > You probably didn't understand what the FAQ says. Do I need to explain?
    > You are supposed to post the _minimal_ _complete_ _compilable_ code that
    > still produces the error you're asking about. It is not enough to see
    > the output statement, two member functions and the wrong output. Do you
    > understand "not enough"? Post the _complete_ program with the effect
    > you are seeing. Then we can discuss a possible cause and solutions. We
    > are not mind readers here.
    >
    > V


    I understand what the FAQ says. I just thought the code I put in the
    message is clear "enough" for the question. Maybe not enough according
    to the group's standard. Then I am sorry for that.

    The code compiles and works fine, except one time recently I saw the
    wrong outputs. So it is not that the code can't compile or has an
    implicit error. I am just wondering how this can happen.

    Thanks for your inputs.
     
    Zhixin Han, Oct 7, 2004
    #5
    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. Parity
    Replies:
    2
    Views:
    396
    Stephen Howe
    Aug 13, 2003
  2. KK
    Replies:
    2
    Views:
    711
    Big Brian
    Oct 14, 2003
  3. Trevor
    Replies:
    2
    Views:
    537
  4. Rock
    Replies:
    4
    Views:
    464
    Jim Langston
    Nov 20, 2005
  5. Replies:
    2
    Views:
    1,973
Loading...

Share This Page