list<int> l;
list<int>::iterator start;
list<int>::iterator end;
list<int>::iterator mid;
for (int i = 0; i < 100; ++i)
l.push_back(i);
start= l.begin();
end= l.end();
mid = start+ (end- start) / 2;
cout << *mid << endl;
Ok, mam teraz konkretny przykład. end-start nie kompiluje się.
Odpowiedzi:
3 dla odpowiedzi № 1list
iterator jest Bidirectional iterator, it"s not
Iterator dostępu losowego. You can"t call
operator - na nim.
możesz po prostu spróbować użyć std::advance
aby przenieść iterator na środek kontenera
std::advance(ble.begin(), ble.size()/2);