- 在线时间
- 0 小时
- 最后登录
- 2005-4-23
- 注册时间
- 2005-1-22
- 听众数
- 0
- 收听数
- 0
- 能力
- 0 分
- 体力
- 161 点
- 威望
- 0 点
- 阅读权限
- 20
- 积分
- 49
- 相册
- 0
- 日志
- 0
- 记录
- 0
- 帖子
- 1
- 主题
- 1
- 精华
- 0
- 分享
- 0
- 好友
- 0
升级   46.32% 该用户从未签到
 |
关于我写了一个代码,想任意生成指定容量的序列式容器,
# h" p: d, K# W但不知道为什么,如果使用iterator的时候,如何进行插入操作。 & S% J0 D1 W0 W& L
#include <vector>
# u- V A3 z" W' g#include <list> ! x" B% h4 U, D9 |( w+ H/ d
#include <deque> 0 O3 L0 w& `% I
#include <iostream> . ?1 x j( Q' I3 Q
#include <cstdlib>
9 E5 \( y/ s/ N! J; Husing namespace std;
4 h- c2 D% W u6 b2 W+ n# q- G1 J$ f( U a% k
template<typename Iter>
9 m4 L% o n0 A# M4 X7 ?Iter generate(Iter iter,int size)
) n2 ^3 f1 F: R9 e{ ) E$ u k$ x. A! k+ v/ _3 b
if(size<=0) {cerr<<"Size is not correct"<<endl;return 0;} 1 ~, ^! {6 ~( b% w' S
srand(100); $ m7 n2 ]: }* n7 L$ U+ d
for(int ix=0;ix<size;ix++) . s. V( ]& i5 c, w: q- z! G1 w: x# N
{iter->insert(rand()%100);}///Something is wrong here!!!
; G) s1 H, O# Q. `+ G6 Q- u9 m @return iter; + g: i+ r% d5 k2 Z: p
} |
zan
|