-3

The requirement is to create an stream, pass it to second function for modification, (it has to be passed in this way since the output need to access private data members of a separate class). and then output the modified stream. It compiles as is but returns only the address of MyStream, I need it to return the stream.

/* Prints the details of the media collection. */
void MediaCollection::PrintMediaDetails() const{
    ostream MyStream(NULL);
    for(int i = 0; i < CurrentMCSize; i++){
        TheCollection[i]->PrintMedia(MyStream);
        cout << i + 1 <<" : "<<&MyStream;
    }
}

/*Takes Stream and and returns data members*/
void Media::PrintMedia(ostream & Out) const{
    Out<<Title<<" "<<Artist<<" "<<&RunningTime<<endl;
}
teneyck
  • 1
  • 1
  • What's the problem? Is it working? How is it working? We are not forecasters. – zoska Mar 19 '14 at 15:54
  • I think, it is clear, what teneyck want to do. He needs an `std::ostringstream`, put into some stuff in the `PrintMedia` method and then outputs `MyStream.str()`. – cpp-progger Mar 19 '14 at 16:23

1 Answers1

0

It is printing the address of MyStream because you are telling it to

Change

<<&MyStream;

to

<<MyStream;

However ostream MyStream(NULL) does not make any sense without passing it a streambuf

cpp-progger suggests using a std::ostringstream. Define one like this

ostringstream MyStream;

and print the contents using

cout << i + 1 <<" : "<< MyStream.str();
David Sykes
  • 48,469
  • 17
  • 71
  • 80