Iterator usage

2013-06-07
2013-06-07
  • Pierre Brico
    Pierre Brico
    2013-06-07

    Hi,

    I'm evaluating the json library and I've found a strange behaviour using the iterator. Here a fragment of code:

    Json::Value::const_iterator i = jsonFields.begin();
    while (i != jsonFields.end())
    {
    DO SOMETHING
    i++;
    }

    This code is performing well: earch Value is given back by the iterator. But the following code crashes:

    Json::Value::const_iterator i;

    i = jsonFields.begin();
    while (i != jsonFields.end())
    {
    DO SOMETHING
    i++;
    }

    The only difference is the split (declaration and initialisation) but the condition i != jsonFields.end() is never true even when the end is reached.

    It is normal ?? Am I doing something wrong ??

    Best regards,
    Pierre