#include <iostream> #include <map> #include <set> #include <iterator> #include <algorithm> #include <string>
std::ostream& operator << (std::ostream& o, const std::pair<std::string, int> p) { o << p.first << " " << p.second << std::endl; return o; } std::ostream& operator << (std::ostream& o, const std::map<std::string,int>& map) { typename std::map<std::string,int>::iterator it = map.begin(); o << "("; while (it != map.end()) { o << *it << ' '; ++it; } o << ")"; return o; } int main() { std::map<std::string,int> map; std::cout << "map=" << map << std::endl; } ----------------------------------------------------------------------------- Here is the compiler output: -*- mode: compilation; default-directory: "~/lisp++-projects/" -*- Compilation started at Thu Jan 25 18:45:22 cd ~/lisp++-projects && make 2018/map/map5.run make: Warning: File '2006/libd/libd.o' has modification time 26862 s in the future * Compiling 2018/map/map5.cc DEBUG g++ -g -O0 -std=c++11 -W -Wall -Wpointer-arith -Wformat -ffast-math -fno-permissive -Wno-format-contains-nul -c 2018/map/map5.cc -o 2018/map/map5.o 2018/map/map5.cc: In function ‘std::ostream& operator<<(std::ostream&, const std::map<std::__cxx11::basic_string<char>, int>&)’: 2018/map/map5.cc:16:63: error: conversion from ‘std::map<std::__cxx11::basic_string<char>, int>::const_iterator {aka std::_Rb_tree_const_iterator<std::pair<const std::__cxx11::basic_string<char>, int> >}’ to non-scalar type ‘std::map<std::__cxx11::basic_string<char>, int>::iterator {aka std::_Rb_tree_iterator<std::pair<const std::__cxx11::basic_string<char>, int> >}’ requested typename std::map<std::string,int>::iterator it = map.begin(); ^ Makefile.mk:66: recipe for target '2018/map/map5.o' failed make: *** [2018/map/map5.o] Error 1 Compilation exited abnormally with code 2 at Thu Jan 25 18:45:24 Compilation started at: 20180125-184522 compilation-start-time=(23145 28402 353882 710000) compilation-stop-time=(23145 28404 423781 491000) Compilation took 2 seconds What gives with the error message? What mm I doing wrong? _______________________________________________ help-gplusplus mailing list help-gplusplus@gnu.org https://lists.gnu.org/mailman/listinfo/help-gplusplus