Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

stevegreen22

macrumors newbie
Original poster
Aug 7, 2012
7
0
Hey guys.

Can someone perhaps help explain this issue I'm having?

Essentially I get an error whenever I add an endl or a out stream to another.

For example:

Code:
      cout << ac.getSizeOfCollection();
Works fine but....
Code:
      cout << ac.getSizeOfCollection() << " Size" <<endl;
Doesn't

I have the same issue with this:

Code:
            cout << "fdsddigifg " << meh.getNumberOfTracks();
//
Works fine but the one below doesn't
Code:
            cout << "fdsddigifg " << meh.getNumberOfTracks() <<" Tracks"<<endl;
//

Any ideas or suggestions? I've tried to trace back the outstream as it's overloaded and every step of the way it's fine. I simply don't understand it. -.-
 

gnasher729

Suspended
Nov 25, 2005
17,980
5,565
Hey guys.

Can someone perhaps help explain this issue I'm having?

Essentially I get an error whenever I add an endl or a out stream to another.

For example:

Code:
      cout << ac.getSizeOfCollection();
Works fine but....
Code:
      cout << ac.getSizeOfCollection() << " Size" <<endl;
Doesn't

I have the same issue with this:

Code:
            cout << "fdsddigifg " << meh.getNumberOfTracks();
//
Works fine but the one below doesn't
Code:
            cout << "fdsddigifg " << meh.getNumberOfTracks() <<" Tracks"<<endl;
//

Any ideas or suggestions? I've tried to trace back the outstream as it's overloaded and every step of the way it's fine. I simply don't understand it. -.-

Try if std::endl makes a difference. Because std::endl is the end of line marker, and endl could be anything. If you added a variable "int endl;" at the beginning of a function that would produce some rather funny results. BTW. Once your programs get larger, you will very much prefer std::cout to cout because it provides a lot more information when you read code.
 

MattMcClinch

macrumors newbie
Jan 24, 2008
8
0
Odds are 'meh.getNumberOfTracks()' is not returning an 'stream&' so there is no stream for 'endl' to do it's thing against.

'meh.getNumberOfTracks()' doesn't need to return a stream&.
'cout << "fdsddigifg " << meh.getNumberOfTracks()' should return a stream&.
'meh.getNumberOfTracks()' should return a nonnegative integer.
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
We don't have enough info. meh.GetNumberOfTracks()... What does it return? Did you write the operator<< method to handle this? How about ac.getSizeOfCollection? Can you output ANYTHING after one of these? Is the problem just endl? What is the problem? A compiler error? What is it? A runtime error? Incorrect results?

-Lee
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.