Since I know an iterator in the program could be invalidated by some previous operation, I want to invalidate it explicitly. Such as assign NULL to a pointer to invalidate i
Why don´t You want to use container.end() ?... it works for most containers...
container.end()
For std::string You may want to check , wether the position is yourstring.npos;
yourstring.npos