数学建模社区-数学中国
标题:
关于C++中的STL的弱弱的问题。
[打印本页]
作者:
运动补偿
时间:
2005-4-17 09:54
标题:
关于C++中的STL的弱弱的问题。
关于我写了一个代码,想任意生成指定容量的序列式容器,
9 t* k/ B4 N* A1 [( G
但不知道为什么,如果使用iterator的时候,如何进行插入操作。
5 l4 X; P1 z) n! \0 W" P6 @6 O+ q
#include <vector>
& w, y% H/ @+ O5 T, X
#include <list>
, T4 b3 l0 I1 A/ }+ `
#include <deque>
! `) ~ C7 U9 }5 ?6 w1 H0 x9 n: l
#include <iostream>
4 J# Y/ Y4 P4 ~0 v* i
#include <cstdlib>
- W: i$ }- s6 Q
using namespace std;
7 d5 M, J0 S+ ]
/ ]- |, w T# w7 Z0 y
template<typename Iter>
0 d! z. g8 ^! [$ L- u: `* [
Iter generate(Iter iter,int size)
9 C) Y4 U+ E- D6 B# e& }. O
{
1 i& d* }" f3 j0 M
if(size<=0) {cerr<<"Size is not correct"<<endl;return 0;}
4 I$ G' b" B; W4 r& e2 \
srand(100);
3 S. N& F$ Y# `2 S f+ M
for(int ix=0;ix<size;ix++)
2 g: Z2 c( z; F! S! k/ v
{iter->insert(rand()%100);}///Something is wrong here!!!
, r! h+ t0 R0 M1 |3 G. w
return iter;
N% ]* R. r. t' Y
}
欢迎光临 数学建模社区-数学中国 (http://www.madio.net/)
Powered by Discuz! X2.5