| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1123 人关注过本帖
标题:[求助]如何输出map?
只看楼主 加入收藏
chenchao
Rank: 1
等 级:新手上路
帖 子:45
专家分:0
注 册:2006-5-20
收藏
 问题点数:0 回复次数:1 
[求助]如何输出map?

在一个类GaloisField中声明了:
private:
std::map<int,int> alpha_to;
...........
public:
friend std::ostream& operator<< (std::ostram& os, const GaloisField& gf)
............


在类定义中构造了alpha_to以及
std::ostream& operator<< (std::ostram& os, const GaloisField& gf)
{
for(int i=-1;i<10;i++)
os<<i<<"\t"
<<gf.alpha_to[i]<<"\n";
return os;
}

编译有错:我查了一下书,说const map 不能使用[ ]运算符。
我有把const去掉了,提示错误:alpha_to为pritive.

那该如何输出呢????







搜索更多相关主题的帖子: map 输出 
2006-06-28 15:48
woodhead
Rank: 3Rank: 3
等 级:新手上路
威 望:9
帖 子:1124
专家分:0
注 册:2005-7-18
收藏
得分:0 
map<int,int>::const_iterator iter = gf.alpha_to.begin();
while(iter != gf.alpha_to.end())
{
os<<iter->first<<' '<<iter->second<<endl;
iter++;
}

2006-06-28 16:17
快速回复:[求助]如何输出map?
数据加载中...
 
   



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

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