QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 2809|回复: 0
打印 上一主题 下一主题

关于C++中的STL的弱弱的问题。

[复制链接]
字体大小: 正常 放大

1

主题

0

听众

49

积分

升级  46.32%

该用户从未签到

新人进步奖

跳转到指定楼层
1#
发表于 2005-4-17 09:54 |只看该作者 |倒序浏览
|招呼Ta 关注Ta
关于我写了一个代码,想任意生成指定容量的序列式容器, 0 P* s) e) \/ m) H
但不知道为什么,如果使用iterator的时候,如何进行插入操作。 3 g, G! m1 h# d+ O: ?' n
#include <vector> 1 Y. w! T1 I2 O+ c
#include <list>
! o/ S! h- d9 _. Q( a' H9 H#include <deque>   B. {$ G( I8 u$ f1 d
#include <iostream> # t, e/ b9 s& Y( G. E& v3 a; g) P" [
#include <cstdlib>
+ v3 o) N6 ~4 jusing namespace std; % x# z3 e% @1 `9 G
. F4 q! w0 r5 B! t
template<typename Iter> 1 o* E: C6 R% b6 F* `4 Z: t
Iter generate(Iter iter,int size) 2 B! @5 z& v2 [) P* J$ c: q0 l
{ * |& H0 m: N* `# a$ \
if(size<=0) {cerr<<"Size is not correct"<<endl;return 0;}
4 A& |1 u: e5 l& Q- csrand(100);
- V# v# Q6 h2 ?4 B# ~" X5 Dfor(int ix=0;ix<size;ix++)
$ o+ r( w* `. x! g8 g2 ?{iter->insert(rand()%100);}///Something is wrong here!!! 0 R. \0 N9 g0 `3 J: R% e9 K) B3 @
return iter; * t6 ?1 |  f. t! @5 E3 ~2 j
}
zan
转播转播0 分享淘帖0 分享分享0 收藏收藏0 支持支持0 反对反对0 微信微信
您需要登录后才可以回帖 登录 | 注册地址

qq
收缩
  • 电话咨询

  • 04714969085
fastpost

关于我们| 联系我们| 诚征英才| 对外合作| 产品服务| QQ

手机版|Archiver| |繁體中文 手机客户端  

蒙公网安备 15010502000194号

Powered by Discuz! X2.5   © 2001-2013 数学建模网-数学中国 ( 蒙ICP备14002410号-3 蒙BBS备-0002号 )     论坛法律顾问:王兆丰

GMT+8, 2025-7-30 02:56 , Processed in 0.457379 second(s), 57 queries .

回顶部