| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 817 人关注过本帖
标题:疯了 这怎么会出问题呢 简单容器迭代器问题
只看楼主 加入收藏
yijing21
Rank: 1
等 级:新手上路
帖 子:48
专家分:0
注 册:2007-11-7
收藏
 问题点数:0 回复次数:4 
疯了 这怎么会出问题呢 简单容器迭代器问题
#include <iostream>
#include <list>
#include <vector>
#include <string>
using namespace std;
int main()
{
    vector<string> ivec;
    ivec.push_back("hy");
    ivec.push_back("hy");
    ivec.push_back("hy");
    ivec.push_back("hy");
    for(vector<string>::iterator i=ivec.begin();i!=[bo]--[/bo]ivec.end();++i)
        cout<<*i;
    vector<string>::iterator it=ivec.begin();
    cout<<*it;
    return 0;
}

这里有3个错误
perfect.cpp(12) : error C2105: '--' needs l-value

error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::a
llocator<char> >' (or there is no acceptable conversion)

error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::a
llocator<char> >' (or there is no acceptable conversion)
首先是ivec.end()为什么不能自减呢  但是换成list容器就可以  自减不是常用容器都可以吗  还有下面那个解引用也不行  今天随便写了下  就发现这些问题  出乎意外  想问问大家

[[it] 本帖最后由 yijing21 于 2008-4-19 15:37 编辑 [/it]]
搜索更多相关主题的帖子: 容器 
2008-04-19 12:04
kaithwin
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2008-2-25
收藏
得分:0 
你没有包含string库
加上#include <string>应该就没有问题了
2008-04-19 15:13
yijing21
Rank: 1
等 级:新手上路
帖 子:48
专家分:0
注 册:2007-11-7
收藏
得分:0 
string库忘了之前 但是加上去是一样的 里面好像涉及到左右值的问题
2008-04-19 15:38
sunkaidong
Rank: 4
来 自:南京师范大学
等 级:贵宾
威 望:12
帖 子:4496
专家分:141
注 册:2006-12-28
收藏
得分:0 
i!=--ivec.end()?没见过谁这样用过

学习需要安静。。海盗要重新来过。。
2008-04-19 16:29
yijing21
Rank: 1
等 级:新手上路
帖 子:48
专家分:0
注 册:2007-11-7
收藏
得分:0 
  我也是在用list容器输出式发现有一项多余项  然后用--vc.end()就可以去掉  但是换成vector才发现这个问题  vc.end()应该是右值 不能自减  但是为什么list容器却可以呢 是巧合还是?
2008-04-19 20:46
快速回复:疯了 这怎么会出问题呢 简单容器迭代器问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017322 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved