This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Need help on compilation (ostream_iterator)
- From: "Eric Gwo" <eric dot gwo at gmail dot com>
- To: libstdc++ at gcc dot gnu dot org
- Date: Sun, 11 May 2008 00:41:31 -0400
- Subject: Need help on compilation (ostream_iterator)
I used
/usr/local/include/c++/3.2.3
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
*/