数学建模社区-数学中国
标题:
关于C++中的STL的弱弱的问题。
[打印本页]
作者:
运动补偿
时间:
2005-4-17 09:54
标题:
关于C++中的STL的弱弱的问题。
关于我写了一个代码,想任意生成指定容量的序列式容器,
, S s! T; N% y9 W. _" l- K0 H
但不知道为什么,如果使用iterator的时候,如何进行插入操作。
/ m/ u' Z/ d* `5 W$ a( F. s, b# @
#include <vector>
9 b0 a2 g. _6 A6 K
#include <list>
- |% B/ z* q$ E. G( g
#include <deque>
% z' Y! \* Q ?5 a$ q
#include <iostream>
. l6 v7 R T& s) s' Q% T ~) ]2 ^4 |
#include <cstdlib>
3 M7 k3 Y6 [/ o [! `
using namespace std;
1 ?- ~; v% L7 D3 }; ^
$ N/ o7 ^/ e# s4 W) w. J
template<typename Iter>
& @- w7 I3 g" X( a. c* s
Iter generate(Iter iter,int size)
5 i) w. @$ D6 c" M7 F M9 H# t
{
* `; h# ^' c, K
if(size<=0) {cerr<<"Size is not correct"<<endl;return 0;}
' w; q: v D2 y* u
srand(100);
, s: Z, l6 r* |, R9 _3 k/ h3 F
for(int ix=0;ix<size;ix++)
, ?) @1 @( M, f
{iter->insert(rand()%100);}///Something is wrong here!!!
+ ^/ m4 z' R5 Z. c$ f. r
return iter;
9 M5 d( ]! W2 n6 F6 E% b+ L' z
}
欢迎光临 数学建模社区-数学中国 (http://www.madio.net/)
Powered by Discuz! X2.5