- 在线时间
- 0 小时
- 最后登录
- 2005-4-23
- 注册时间
- 2005-1-22
- 听众数
- 0
- 收听数
- 0
- 能力
- 0 分
- 体力
- 161 点
- 威望
- 0 点
- 阅读权限
- 20
- 积分
- 49
- 相册
- 0
- 日志
- 0
- 记录
- 0
- 帖子
- 1
- 主题
- 1
- 精华
- 0
- 分享
- 0
- 好友
- 0
升级   46.32% 该用户从未签到
 |
关于我写了一个代码,想任意生成指定容量的序列式容器, . W- R, B& a' S& J5 E% E
但不知道为什么,如果使用iterator的时候,如何进行插入操作。
& i- Q; F+ h! _% }#include <vector>
7 x0 e9 g$ r) { f/ J5 m j a9 |" v#include <list>
. ~3 H/ ^* t' w+ H#include <deque> 0 |) P* j5 J% R; k3 ~9 R. ?
#include <iostream>
- u$ P/ l0 L% Z#include <cstdlib>
( H5 J4 m, o/ E% x8 X7 {! n5 G8 `using namespace std;
0 q+ @* o& |6 v% _ b3 [5 l6 L) e; I$ ?
template<typename Iter>
5 `# Q. V n& u% ]. t' qIter generate(Iter iter,int size)
' d; W1 d/ [7 c c+ D. U0 A{
, ~% ~5 ]+ i& A! ]9 x! v8 Lif(size<=0) {cerr<<"Size is not correct"<<endl;return 0;} / T) c* [7 V2 }1 P& ^( x$ V( T
srand(100);
/ H1 }) i$ U( L0 Vfor(int ix=0;ix<size;ix++) " ^7 p/ J/ T4 w; A
{iter->insert(rand()%100);}///Something is wrong here!!!
, `: J$ |/ N# ~$ O3 L3 z2 xreturn iter;
; Y/ R U5 }2 E" k, w7 K; Y} |
zan
|