Help me with list

Hi, i want find this position of elemento 69 in list that is 4. This my code:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>
#include <list>

using namespace std;

int main()
{
    list<int> sexo;
    list<int>::iterator it;
    int cont = 0;

    sexo.push_back(5);
    sexo.push_back(3);
    sexo.push_back(4);
    sexo.push_back(69);
    sexo.push_back(33);
    sexo.push_back(15);
    sexo.push_back(2);
    sexo.push_back(1);

    for(it = sexo.begin(); it != sexo.end(); it++){
        cont++;
        if(*it == 69){
            it = sexo.end();
        }
    }

    cout << "cont = " << cont << endl;
    return 0;
}
Add a break:
1
2
3
4
5
6
7
    for(it = sexo.begin(); it != sexo.end(); it++){
        cont++;
        if(*it == 69){
            it = sexo.end();
            break; // Note
        }
    }
Topic archived. No new replies allowed.