Unnötig mehr als der folgenden Code zu sagen:Warum funktioniert ostream_iterator nicht wie erwartet?
#include <utility>
#include <vector>
#include <iostream>
#include <iterator>
using namespace std;
typedef pair<char, char> PAIR;
ostream& operator <<(ostream& os, const PAIR& r)
{
return os << r.first;
}
int main()
{
vector<PAIR> coll;
cout << coll[0]; // OK.
// The following line will cause a compilation error! Why???
copy(coll.begin(), coll.end(), ostream_iterator<PAIR>(cout));
}
Können Sie erläutern, wie Ihre spätere Lösung funktioniert? –
@ IvanZ.Siu: Siehe mein Update. – wilx