I'm trying out VSCode writing some C++ using gdb, and I am finding that I need to determine what element an iterator
is pointing at for a particular vector
. Is there some way of doing this?
If you're trying to do this as part of your program, you can use STL:
int distance = std::distance(begin(s), result);
If you're trying to do this using the watch window in VSCode, the above will not work, as it's calling a function. Since the underlying structure of a vector is an array, you can use math instead. In the watch window, add:
(&(*myIterator) - &(myVector[0])) / sizeof(myVector[0])
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.