标题:[求助]如何输出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



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-75417-1-1.html




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

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