Namespaces when used with ostream_iterators?

  • Thread starter Robert J. Hansen
  • Start date
R

Robert J. Hansen

In the following code:

=====

#include <iostream>
#include <iterator>
#include <algorithm>
#include <vector>

using std::eek:stream_iterator;
using std::copy;
using std::cout;
using std::endl;
using std::vector;
using std::eek:stream;

namespace example {
struct A
{
};
}

ostream& operator<<(ostream& os, const example::A& a)
{
os << "Foo! ";
return os;
}

int main()
{
vector<example::A> foo(1);
cout << foo.at(0) << endl;

// ostream_iterator<example::A> bar(cout, "\n");
// copy(foo.begin(), foo.end(), bar);

return 0;
}

=====

I can use the operator<< for the first statement to cout without any
problems. When attempting to use an ostream_iterator and copy() to
achieve the same effect, I get tons of incomprehensible STL errors.
Using gfilt on it--yes, I know gfilt doesn't officially support G++ 4
yet, but I've had good experiences using it to simplify things
nevertheless--I get:

BD Software STL Message Decryptor v2.47a for gcc
stream_iterator.h: In member function 'ostream_iterator<
example::A said:
> & ostream_iterator<example::A, char, char_traits<char>
::eek:perator=(
const example::A &
)':
[STL Decryptor: Suppressed 4 more STL standard header messages]
test.cc:30: instantiated from here
stream_iterator.h:196: error: no match for 'operator<<' in '*(
(ostream_iterator said:
::_M_stream <<
__value'


.... which is still not especially helpful to me.

Can someone help me out with figuring out precisely what invocation I
need to introduce in order to get ostream_iterator to support the
output of namespaced types?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,078
Latest member
MakersCBDBlood

Latest Threads

Top