How can I detect the last iteration in a loop over std::map?

前端 未结 15 1371
深忆病人
深忆病人 2021-01-01 10:24

I\'m trying to figure out the best way to determine whether I\'m in the last iteration of a loop over a map in order to do something like the following:

for          


        
15条回答
  •  清酒与你
    2021-01-01 11:09

    Why to work to find the EOF so that you dont give something to it.

    Simply, exclude it;

    for (iter = someMap.begin(); someMap.end() - 1; ++iter) {
        //apply to all from begin to second last element
    }
    

    KISS (KEEP IT SIMPLY SIMPLE)

提交回复
热议问题