首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

关于iterator的程序异常

2012-02-11 
关于iterator的程序错误这段代码在VC里运行为什么会有六个错误呢,应该怎么改啊#includevector//引用参数

关于iterator的程序错误
这段代码在VC里运行为什么会有六个错误呢,应该怎么改啊

#include   <vector>
//   引用参数   'occurs '   可以含有第二个返回值
vector <int> ::const_iterator   look_up(
const   vector <int>   &vec,
int   value,   //   值在vector   中吗?
int   &occurs   )   //   多少次?
{
//   res_iter   被初始化为最后一个元素的下一位置
vector <int> ::const_iterator   res_iter   =   vec.end();
occurs   =   0;
for   (   vector <int> ::const_iterator   iter   =   vec.begin();
iter   !=   vec.end();
++iter   )
if   (   *iter   ==   value   )
{
if   (   res_iter   ==   vec.end()   )
res_iter   =   iter;
++occurs;
}
return   res_iter;
}

错误如下:
error   C2143:   syntax   error   :   missing   '; '   before   ' < '
error   C2501:   'vector '   :   missing   storage-class   or   type   specifiers
error   C2143:   syntax   error   :   missing   '; '   before   ' < '
error   C2039:   'const_iterator '   :   is   not   a   member   of   '`global   namespace ' '
error   C2143:   syntax   error   :   missing   '; '   before   '{ '
error   C2447:   missing   function   header   (old-style   formal   list?)
Error   executing   cl.exe.

test1.obj   -   6   error(s),   0   warning(s)


[解决办法]
using namespace std;
[解决办法]
#include <vector>
using namespace std;

热点排行