Lower Bound-STL

  • + 1 comment
    int main() {
        int size;
        cin >> size;
        vector<int> vec(size);
    
        int input;
        for(int it = 0; it < size; it++){
            cin >> input;
            vec[it] = input;
        }
        vector<int>::iterator vIt;
    
        int queries;
        cin >> queries;
        int comp;
        for (int it = 0; it < queries; it++){
            cin >> comp;
            vIt = lower_bound(vec.begin(), vec.end(), comp);
            if(comp == *vIt) cout << "Yes " << (vIt - vec.begin() + 1) << endl;
            else cout << "No " << (vIt - vec.begin() + 1) << endl;
        }
        return 0;
    }
    

    Can someone help me understand why we have to go through such lengths to be able to access the iterator value from vector::iterator. As in, why do I have to take away vec.begin() from it (I'm assuming vec.begin would just return 0 for the first it in a vector.