习题问题

opposever 2008-05-01 12:16:19
#include <iostream>
#include <vector>
#include <string>
using namespace std;

bool exist(vector<int>::iterator beg,vector<int>::iterator end,int ival)
{

while (beg!=end)
if(*beg==ival) //if find,end
break;
else
++beg;
if (beg!=end)
return true;
else
return false;
}

int main()//在vector中找给定的int型数值
{
int i=2;
//cout<<"please enter one int value:"<<endl;
//cin>>i;
int ia[10]={0,1,2,3,4,5,6,7,8,9};
vector<int> ivec(ia,ia+10);
vector<int>::iterator b=ivec.begin(),e=ivec.end();
exist(b,e,i);//if exist i,return ture;else,return false
cout<<exist<<endl;
return 0;

}
C++primer 习题9.11;编写函数实现迭代器标记的范围内寻找该int型数值的功能,并返回一个bool结果,指明是否找到指定数据。
这个程序编译能通过,但结果是004012DA,是哪里的问题?
...全文
38 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
jackiewlb 2008-05-04
  • 打赏
  • 举报
回复
你在cout中使用exist,
exist会转换成函数指针
因此输出的是函数的地址。
可以用一个bool变量保存返回值再输出
或者直接用:cout < <exist(b,e,i) < <endl

64,654

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧