pos
is an iterator to the lower bound of q
. Here q
is a long long integer and prefix
is a vector which stores long long elements.
vector <int> :: iterator pos;
pos = lower_bound(prefix.begin(), prefix.end(), q);
I get the following error:
no operator "=" matches these operands -- operand types are: __gnu_cxx::__normal_iterator<int *, std::vector<int, std::allocator<int>>> = __gnu_cxx::__normal_iterator<long long *, std::vector<long long, std::allocator<long long>>>
Is there any way to fix this?
Your declaration of pos
is incorrect. You vector - prefix
is of declared as vector<long long>prefix;
. The iterator should also be of the same type.
You can try using the following -
vector<long long>::iterator pos = lower_bound(prefix.begin(), prefix.end(), q);
You can always choose the following syntax as well if you are not sure of how to declare the variable(iterator in this case) properly :
auto pos = lower_bound(prefix.begin(), prefix.end(), q);
The auto
keyword can only be used in C++11 and above. But, if you are sure of the syntax and type of the variable you are declaring, it's always preferable to declare it manually rather than having it inferred by your program. It will increase the reliability as well as readability of your program.
Hope this solves your issue !