This is the mail archive of the mailing list for the libstdc++ project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Need help on compilation (ostream_iterator)

I used
to compile the following codes:
(it works for line1 but not works for line2, why?
please help and advise! thank you!)

--------------- code pieces -----------

class MonthMap: public map<string, int>


typedef MonthMap::value_type MonthMapElement;
typedef MonthMap::iterator MonthIterator;

ostream& operator<<(ostream & aOstream, const MonthMap::value_type& p)
       aOstream << p.first << " has " << p.second << " days";
       return aOstream;

int main()
MonthMap aMap;
MonthMap::iterator p;
ostream_iterator<MonthMapElement> aOI(cout, "\n");

        for (p=aMap.begin(); p!=aMap.end(); p++)
                cout << *p << endl;      //.......................line 1
                //*aOI++ = *p;              //.......................line  2

/* When line2 is un-commented, the compiler complaint
/usr/local/include/c++/3.2.3/bits/stream_iterator.h: In member function
   `std::ostream_iterator<_Tp, _CharT, _Traits>& std::ostream_iterator<_Tp,
   _CharT, _Traits>::operator=(const _Tp&) [with _Tp = MonthMapElement, _CharT
   = char, _Traits = std::char_traits<char>]':
OstreamIterator.cpp:53:   instantiated from here
/usr/local/include/c++/3.2.3/bits/stream_iterator.h:141: no match for `
   std::basic_ostream<char, std::char_traits<char> >& << const std::pair<const
   std::string, int>&' operator

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]