STL string end() iterator

Status
Not open for further replies.
Is it defined anywhere what happens if I run code such as:
code:<HR>
Code:
void end_iterator(void)
{
	std::string s = "iterator test";
	std::string::const_iterator si;<P>	char c = *si.end();<P>	std::cout << c << std::endl;
}
That is, will something predictable happen when I try to dereference the end() iterator of a string (or, I suppose, of another sequence or hash)?

Using C, the equivalent operation (dereference the pointer to one character beyond the last non-NULL one) always produces NULL; it would be nice to know something similar about the STL string.
 
Originally posted by PeterB:
I believe that you shouldn't dereference such iterators, and that they're not guaranteed to do anything sensible. But I might not be remembering right.
You can dereference iterators as they act as pointers to the objects, but I think that our friend BlackClaw's problem is that he is dereferencing .end() which is not valid. Remember, .end() is past the end of the string and is used to indicate that fact.

dlr(2)

EDIT: apologies for reacting to PeterB's post and not responding to the original :D -> afaik, no there is no 'language guarantee' about what .end() is. For some compilers, a NULL could be used but this is not guaranteed.
 
Status
Not open for further replies.