Question: I would like to traverse a map in C++ with iterators but not all the way to the end.
The problem is that even if we can do basic operations with iterators, we cannot add or compare iterators with integers.
How can I write the following instructions? (`final` is a map; `window`, an integer)

```
for (it=final.begin(); it!=final.end()-window; it++)

```

Answer: 
You cannot subtract from a map iterator directly, because it is an expensive operation (in practice doing --iter the required number of times). If you really want to do it anyway, you can use the standard library function 'advance'. 

```
map<...>::iterator end = final.end();
std::advance(end, -window);

```

That will give you the end of your window.
Why don't you make 'it' an iterator as well ? 

See the example here : <http://www.cplusplus.com/reference/stl/map/begin/>