[xsd-users] Erasing elements

Andrew Ward andy.ward at hevday.com
Sun May 7 23:10:40 EDT 2006


Hi,
Using the hello.xsd example from the XSD website and the following code:

#include <iostream>
#include "hello.hxx"

int main()
{
    hello_type ht("hi");
    ht.name().push_back("1");
    ht.name().push_back("2");
    ht.name().push_back("3");

    hello_type::name::iterator it(ht.name().begin()), end(ht.name().end());
  
    while(it != end)
    {
        std::cout << "erasing " << (*it) << std::endl;
        it = ht.name().erase(it);
        if(it != end)
            std::cout << (*it) << " comes next" << std::endl;
        else
            std::cout << "all erased" << std::endl;
    }
}

After "3" is erased "it != end" still evaluates to true and the program 
crashes. Is this code valid and is there an alternative?

Regards,
Andrew Ward.






More information about the xsd-users mailing list