数学建模社区-数学中国

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

作者: 运动补偿    时间: 2005-4-17 09:54
标题: 关于C++中的STL的弱弱的问题。
关于我写了一个代码,想任意生成指定容量的序列式容器, 8 J& }  S) z/ v
但不知道为什么,如果使用iterator的时候,如何进行插入操作。 ) U+ ~2 ~9 b  G! q$ Q( f
#include <vector> $ U9 w# X$ p7 b7 M6 p# i2 `
#include <list> ; ~5 l3 y8 f* J" j  y6 H" f5 C
#include <deque> ' F2 g8 E  ]$ B: J
#include <iostream>
# C( B! V2 a8 {8 Y#include <cstdlib> 9 ]1 r1 z2 i  Q  `5 j
using namespace std; 7 Z; K/ ]7 \; G0 H8 B+ Q8 T+ W
: W; p* e& h* O+ R' G# r% \+ b
template<typename Iter> , z$ F% k5 ?% u; K4 V4 Y
Iter generate(Iter iter,int size) : k, i+ N: r5 {3 x  g- Z
{ 3 D3 N, d7 y4 R$ O
if(size<=0) {cerr<<"Size is not correct"<<endl;return 0;} ! U. d% ~6 l- h1 z
srand(100); 8 N. l9 J9 N* t! E; f% r
for(int ix=0;ix<size;ix++) / j/ g% G% X1 t9 Y8 y3 [. z
{iter->insert(rand()%100);}///Something is wrong here!!!
! m5 r* o( B5 s5 r( b6 ureturn iter; * k9 i2 F) S+ J% A0 C- j% O
}




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