List的Iterator

  写个小程序,用到了List,而且要用到它的Iterator,由于以前有用vector的经验,想当然的在Iterator上做了一个+3的操作,结果报错。当时FT,然后开始写测试程序,顺便上网去转转,结果程序写到一半的时候,看到篇文章比较各种Iterator,然后明白了,List的Iterator是双向的,而vector的Iterator是random的,就有了对+n这一操作支持的不同,而从前没看过的我就稀里糊涂的FT了。写下来,防止以后再稀里糊涂,嗯。

This entry was posted in Happy coding. Bookmark the permalink.

3 Responses to List的Iterator

  1. fanq says:

    朋友,说的具体点可以吗?
    我看了半天也没明白,我想在list 用 Iterator时往后比如 +n 操作是错的,怎样才能办到呢? 做n次++ 那就不用说的。

  2. Sonic says:

    @fanq: STL中List的Iterator是双向Iterator,不支持直接+n的操作,如果要使用+n的操作,需要使用random的Iterator,就是使用vector。我不清楚能不能在List中使用Vector的Iterator。
    应该说清楚了吧,呵呵 ^_^

  3. fanq says:

    谢谢!

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>