写个小程序,用到了List,而且要用到它的Iterator,由于以前有用vector的经验,想当然的在Iterator上做了一个+3的操作,结果报错。当时FT,然后开始写测试程序,顺便上网去转转,结果程序写到一半的时候,看到篇文章比较各种Iterator,然后明白了,List的Iterator是双向的,而vector的Iterator是random的,就有了对+n这一操作支持的不同,而从前没看过的我就稀里糊涂的FT了。写下来,防止以后再稀里糊涂,嗯。
写个小程序,用到了List,而且要用到它的Iterator,由于以前有用vector的经验,想当然的在Iterator上做了一个+3的操作,结果报错。当时FT,然后开始写测试程序,顺便上网去转转,结果程序写到一半的时候,看到篇文章比较各种Iterator,然后明白了,List的Iterator是双向的,而vector的Iterator是random的,就有了对+n这一操作支持的不同,而从前没看过的我就稀里糊涂的FT了。写下来,防止以后再稀里糊涂,嗯。
This entry was posted on 2007-08-15, 17:09 and is filed under Happy coding. You can follow any responses to this entry through RSS 2.0. You can skip to the end and leave a response. Pinging is currently not allowed.
Fusion theme by digitalnature | powered by WordPress
Entries (RSS) and Comments (RSS) ^
#1 by fanq on 2008-11-28 - 15:17
朋友,说的具体点可以吗?
我看了半天也没明白,我想在list 用 Iterator时往后比如 +n 操作是错的,怎样才能办到呢? 做n次++ 那就不用说的。
#2 by Sonic on 2008-11-28 - 17:47
@fanq: STL中List的Iterator是双向Iterator,不支持直接+n的操作,如果要使用+n的操作,需要使用random的Iterator,就是使用vector。我不清楚能不能在List中使用Vector的Iterator。
应该说清楚了吧,呵呵 ^_^
#3 by fanq on 2008-12-26 - 18:54
谢谢!