数学建模社区-数学中国

标题: 关于C++中的STL的弱弱的问题。 [打印本页]

作者: 运动补偿    时间: 2005-4-17 09:54
标题: 关于C++中的STL的弱弱的问题。
关于我写了一个代码,想任意生成指定容量的序列式容器, 3 Q9 c3 {2 X0 P/ S7 Q+ g5 e7 o7 s
但不知道为什么,如果使用iterator的时候,如何进行插入操作。
/ y- B; Z2 V# J! p. j/ d% I1 o2 R5 ]#include <vector>
* w. C4 a+ e5 P; t) ?9 D+ P* s#include <list> 1 f- {3 z' g5 o
#include <deque>
% i, c6 N4 r6 g* T#include <iostream> * f- D& F) E; }6 ^( q
#include <cstdlib>
" c& C, L" ?: |using namespace std;
% M8 v; R' J& a- U9 w$ i$ b
+ T/ J- b7 @  b- T2 i' }template<typename Iter> 2 _1 H3 i+ Z/ Z
Iter generate(Iter iter,int size) ; E! g6 V* s+ `2 q" {7 U4 W
{   d% b4 c( B# `; i/ o8 K
if(size<=0) {cerr<<"Size is not correct"<<endl;return 0;}
& M$ h' U8 L1 O. A) d; M7 F% qsrand(100);
& e: ~; b+ n0 ~; I# P/ }% efor(int ix=0;ix<size;ix++)
9 W: W* _+ N# O3 u{iter->insert(rand()%100);}///Something is wrong here!!!
1 i& ]* L& d4 f7 i* xreturn iter; 8 N& C& Q! h" p" {/ V' w" Y
}




欢迎光临 数学建模社区-数学中国 (http://www.madio.net/) Powered by Discuz! X2.5