Hello there!
So I'm trying to compute an iterator that points to the middle element of a vector
1 2 3 4 5 6 7 8 9
|
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<int> vec(10, 333);
vector<int>::iterator mid = (vec.end() + vec.begin()) / 2;
return 0;
}
|
This is supposed to work, right?
But I'm getting the following error:
error: invalid operands to binary expression ('iterator' (aka '__wrap_iter<pointer>') and 'iterator')
vector<int>::iterator mid = (vec.end() + vec.begin()) / 2;
Is it because of my current c++ version?
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.0.0 (clang-700.0.72)
Target: x86_64-apple-darwin14.5.0
Thread model: posix
This is a basic operation I'm even seeing in a C++ book, yet it won't work. Could someone please explain to me what's going on?
Thanks,