This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Should this work?


	std::cout << os.str().end() - os.str().begin() << std::endl;
}

It looks like os.str().end() and os.str().begin() are iterators over
different sequences, so you get some strange results. It's easy to fix
by using a temporary

string temp = os.str();

but I was wondering if it exhibits the correct behaviour without the
temporary?

The behaviour is undefined without the temporary: the str() function returns a string 'object' (not a reference to a string). Therefore, the two calls to str() produce different objects, the two iterators refer to different sequences, and the subtraction yields an undefined result.
Whatever the behavior - it is 'correct' - but it is also probably not
what you want.

Jack


_________________________________________________________________
MSN Photos is the easiest way to share and print your photos: http://photos.msn.com/support/worldwide.aspx


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]