声明一个类型的变量iter
:
void Routes::viewroutes(){
typedef map<char*, char*>::const_iterator iter;
for (iter i =rtable.begin(); i != rtable.end(); ++i) {
cout << i->second << " " << i->first << endl;
}
}
只是为了好玩:),您可以使用我编写的以下函数将映射或多映射的内容流式传输到任何标准流,无论是标准输出还是文件流。它处理所有类型的流,例如 cout 或 wcout:
template <class Container, class Stream>
Stream& printPairValueContainer(Stream& outputstream, const Container& container)
{
typename Container::const_iterator beg = container.begin();
outputstream << "[";
while(beg != container.end())
{
outputstream << " " << "<" << beg->first << " , " << beg->second << ">";
beg++;
}
outputstream << " ]";
return outputstream;
}
template
< class Key, class Value
, template<class KeyType, class ValueType, class Traits = std::less<KeyType>,
class Allocator = std::allocator<std::pair<const KeyType, ValueType> > >
class Container
, class Stream
>
Stream& operator<<(Stream& outputstream, const Container<Key, Value>& container)
{
return printPairValueContainer(outputstream, container);
}