Thread: ostream& outrage !!!

  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    12

    Question ostream& outrage !!!

    Code:
    const ostream& Diver:: list(ostream& out_tr) const
    {
    	cout<<"I am the trouble";
    	cout<<id_;
    	cout<<"Or me";
    	out_tr<<name_<<" "<<country_<<" ";
    	cout<<"The hole is here";
    	out_tr<<tmp_avg_<<endl;
    	
    	return out_tr;
    }
    >>> compilation passed
    and then trouble
    I use member.list(cout)
    in main()
    those lousy outputs are my attempt to find problem, but always failed after "I am the trouble"

    or should it be like this?
    Code:
    const ostream& Diver:: list(ostream& out_tr) const
    {
    		cout<<id_<<" "name_<<" "<<country_<<" "<<tmp_avg_<<endl;
    	
    	return out_tr;
    }

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Are you certain that the stream represented by out_tr is open?
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    What problem?
    I recommend writing debug output to cerr, or at least flushing cout after EACH output.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #4
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    >>but always failed after "I am the trouble"
    You mean, "I am the touble" didn't output correctly, or do you mean id_ didn't output correctly? If id_ failed, then chances are:
    a) id_ is an unsigned char or pointer to a datatype other than char
    b) or id_ is filled with some 'garbage' value
    c) or the whole object is filled with some 'garbage' values, i.e. it wasn't initialized.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. ostream&
    By msshapira in forum C++ Programming
    Replies: 5
    Last Post: 05-07-2009, 10:13 AM