Answers:
您可以像下面这样实现:
map<string, int>::iterator it;
for ( it = symbolTable.begin(); it != symbolTable.end(); it++ )
{
    std::cout << it->first  // string (key)
              << ':'
              << it->second   // string's value 
              << std::endl ;
}
使用C ++ 11 (及更高版本),
for (auto const& x : symbolTable)
{
    std::cout << x.first  // string (key)
              << ':' 
              << x.second // string's value 
              << std::endl ;
}
使用C ++ 17 (及更高版本),
for( auto const& [key, val] : symbolTable )
{
    std::cout << key         // string (key)
              << ':'  
              << val        // string's value
              << std::endl ;
}
              auto const& [key, val] : symbolTable格式!
                    尝试以下
for ( const auto &p : table )
{
   std::cout << p.first << '\t' << p.second << std::endl;
} 
可以使用普通的for循环编写相同的内容
for ( auto it = table.begin(); it != table.end(); ++it  )
{
   std::cout << it->first << '\t' << it->second << std::endl;
} 
考虑到value_type为std::map以下方式定义
typedef pair<const Key, T> value_type
因此,在我的示例中,p是对value_type的const引用,其中Key是std::string,T是int
如果将函数声明为
void output( const map<string, int> &table );
              所述value_type的map是一种pair含有该键和值,因为它的first和second分别构件。
map<string, int>::iterator it;
for (it = symbolTable.begin(); it != symbolTable.end(); it++)
{
    std::cout << it->first << ' ' << it->second << '\n';
}
或使用C ++ 11,将基于范围的用于:
for (auto const& p : symbolTable)
{
    std::cout << p.first << ' ' << p.second << '\n';
}